xref: /PHP-7.3/Zend/tests/gc_017.phpt (revision 153b27df)
1--TEST--
2GC 017: GC and destructors with unset
3--INI--
4zend.enable_gc=1
5--FILE--
6<?php
7class Node {
8	public $name;
9	public $children;
10	public $parent;
11	function __construct($name) {
12		$this->name = $name;
13		$this->parent = null;
14	}
15	function insert($node) {
16		$node->parent = $this;
17		$this->children[] = $node;
18	}
19	function __destruct() {
20		var_dump($this->name);
21		unset($this->name);
22		unset($this->children);
23		unset($this->parent);
24	}
25}
26$a = new Node('A');
27$b = new Node('B');
28$c = new Node('C');
29$a->insert($b);
30$a->insert($c);
31unset($a);
32unset($b);
33unset($c);
34var_dump(gc_collect_cycles() >= 7);
35echo "ok\n"
36?>
37--EXPECTF--
38string(1) "%s"
39string(1) "%s"
40string(1) "%s"
41bool(true)
42ok
43