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