mirror of
https://github.com/php/php-src.git
synced 2024-12-25 01:40:50 +08:00
60a7e60b61
For objects with destructors, we will now only call the destructor in the initial GC run, and remove any nested data. The object is marked purple so it will be considered a root for the next GC run, at which point it will be fully destroyed, if possible. GC counts change on a number of tests, as the objects now get destroyed later.
45 lines
718 B
PHP
45 lines
718 B
PHP
--TEST--
|
|
GC 017: GC and destructors with unset
|
|
--INI--
|
|
zend.enable_gc=1
|
|
--FILE--
|
|
<?php
|
|
class Node {
|
|
public $name;
|
|
public $children;
|
|
public $parent;
|
|
function __construct($name) {
|
|
$this->name = $name;
|
|
$this->parent = null;
|
|
}
|
|
function insert($node) {
|
|
$node->parent = $this;
|
|
$this->children[] = $node;
|
|
}
|
|
function __destruct() {
|
|
var_dump($this->name);
|
|
unset($this->name);
|
|
unset($this->children);
|
|
unset($this->parent);
|
|
}
|
|
}
|
|
$a = new Node('A');
|
|
$b = new Node('B');
|
|
$c = new Node('C');
|
|
$a->insert($b);
|
|
$a->insert($c);
|
|
unset($a);
|
|
unset($b);
|
|
unset($c);
|
|
var_dump(gc_collect_cycles());
|
|
var_dump(gc_collect_cycles());
|
|
echo "ok\n"
|
|
?>
|
|
--EXPECTF--
|
|
string(1) "%s"
|
|
string(1) "%s"
|
|
string(1) "%s"
|
|
int(0)
|
|
int(1)
|
|
ok
|