xref: /php-src/Zend/tests/gh13670_003.phpt (revision bb6b659a)
1--TEST--
2GH-13670 003
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
59// Result of array_slice() is a tmpvar that will be checked by
60// zend_gc_check_root_tmpvars()
61foreach (array_slice($objs, -10) as $obj) {
62    $o = $obj;
63}
64
65$st = gc_status();
66
67if ($st['runs'] > 10) {
68    var_dump($st);
69}
70?>
71==DONE==
72--EXPECT--
73==DONE==
74