bug70805.phpt 1015 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. --TEST--
  2. Bug #70805 (Segmentation faults whilst running Drupal 8 test suite)
  3. --FILE--
  4. <?php
  5. class A {
  6. }
  7. class B {
  8. }
  9. class C {
  10. public function __destruct() {
  11. if (isset($GLOBALS["a"])) {
  12. unset($GLOBALS["array"]);
  13. unset($GLOBALS["a"]); // this will be called in gc_colloct_roots and put $a into gc roots buf
  14. }
  15. }
  16. }
  17. $a = new A;
  18. $a->b = new B;
  19. $a->b->a = $a;
  20. $i = 0;
  21. $c = new A;
  22. $array = array($c); //This is used to leave a room for $GLOBALS["a"]
  23. unset($c);
  24. while ($i++ < 9998) {
  25. $t = [];
  26. $t[] = &$t;
  27. unset($t);
  28. }
  29. $t = [new C];
  30. $t[] = &$t;
  31. unset($t); // This is used to trigger C::__destruct while doing gc_colloct_roots
  32. $e = $a;
  33. unset($a); // This one can not be putted into roots buf because it's full, thus gc_colloct_roots will be called,
  34. // but C::__destructor which is called in gc_colloct_roots will put $a into buf
  35. // which will make $a be putted into gc roots buf twice
  36. var_dump(gc_collect_cycles());
  37. ?>
  38. --EXPECT--
  39. int(0)