xref: /PHP-8.3/Zend/tests/gh13670_002.phpt (revision bb6b659a)
1--TEST--
2GH-13670 002
3--SKIPIF--
4<?php
5// gc_threshold is global state
6if (getenv('SKIP_REPEAT')) die('skip Not repeatable');
7?>
8--FILE--
9<?php
10
11register_shutdown_function(function () {
12    global $shutdown;
13    $shutdown = true;
14});
15
16class Cycle {
17    public $self;
18    public function __construct() {
19        $this->self = $this;
20    }
21}
22
23class Canary {
24    public $self;
25    public function __construct() {
26        $this->self = $this;
27    }
28    public function __destruct() {
29        global $shutdown;
30        if (!$shutdown) {
31            work();
32        }
33    }
34}
35
36function work() {
37    global $objs, $defaultThreshold;
38    new Canary();
39    // Create some collectable garbage so the next run will not adjust
40    // threshold
41    for ($i = 0; $i < 100; $i++) {
42        new Cycle();
43    }
44    // Add potential garbage to buffer
45    foreach (array_slice($objs, 0, $defaultThreshold) as $obj) {
46        $o = $obj;
47    }
48}
49
50$defaultThreshold = gc_status()['threshold'];
51$objs = [];
52for ($i = 0; $i < $defaultThreshold*2; $i++) {
53    $obj = new stdClass;
54    $objs[] = $obj;
55}
56
57work();
58
59foreach ($objs as $obj) {
60    $o = $obj;
61}
62
63$st = gc_status();
64
65if ($st['runs'] > 10) {
66    var_dump($st);
67}
68?>
69==DONE==
70--EXPECT--
71==DONE==
72