xref: /PHP-7.4/Zend/tests/gc_029.phpt (revision 60a7e60b)
1--TEST--
2GC 029: GC and destructors
3--INI--
4zend.enable_gc=1
5--FILE--
6<?php
7class Foo {
8	public $bar;
9	public $x = array(1,2,3);
10	function __destruct() {
11		if ($this->bar !== null) {
12			$this->x = null;
13			unset($this->bar);
14		}
15	}
16}
17class Bar {
18	public $foo;
19        function __destruct() {
20                if ($this->foo !== null) {
21                        unset($this->foo);
22                }
23        }
24
25}
26$foo = new Foo();
27$bar = new Bar();
28$foo->bar = $bar;
29$bar->foo = $foo;
30unset($foo);
31unset($bar);
32var_dump(gc_collect_cycles());
33var_dump(gc_collect_cycles());
34?>
35--EXPECT--
36int(0)
37int(1)
38