xref: /PHP-7.4/Zend/tests/bug77345_gc_1.phpt (revision 5da591c5)
1--TEST--
2Bug #77345 (Segmentation faults stack overflow in cyclic garbage collector) (Bug #77427)
3--INI--
4zend.enable_gc = 1
5--FILE--
6<?php
7
8class Node
9{
10    /** @var Node */
11    public $previous;
12    /** @var Node */
13    public $next;
14}
15
16var_dump(gc_enabled());
17var_dump('start');
18
19$firstNode = new Node();
20$firstNode->previous = $firstNode;
21$firstNode->next = $firstNode;
22
23$circularDoublyLinkedList = $firstNode;
24
25for ($i = 0; $i < 200000; $i++) {
26    $currentNode = $circularDoublyLinkedList;
27    $nextNode = $circularDoublyLinkedList->next;
28
29    $newNode = new Node();
30
31    $newNode->previous = $currentNode;
32    $currentNode->next = $newNode;
33    $newNode->next = $nextNode;
34    $nextNode->previous = $newNode;
35
36    $circularDoublyLinkedList = $nextNode;
37}
38var_dump('end');
39--EXPECT--
40bool(true)
41string(5) "start"
42string(3) "end"