gc_017.phpt 755 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. --TEST--
  2. GC 017: GC and destructors with unset
  3. --INI--
  4. zend.enable_gc=1
  5. --FILE--
  6. <?php
  7. class 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);
  31. unset($a);
  32. unset($b);
  33. unset($c);
  34. var_dump(gc_collect_cycles());
  35. echo "ok\n"
  36. ?>
  37. --EXPECTF--
  38. string(1) "%s"
  39. string(1) "%s"
  40. string(1) "%s"
  41. int(1)
  42. ok