xref: /PHP-8.1/ext/spl/tests/bug65387.phpt (revision c2a8934b)
1--TEST--
2Bug #67387: Circular references in SPL iterators are not garbage collected
3--FILE--
4<?php
5
6$it = new ArrayIterator([1, 2, 3]);
7// Inner.
8$it[] = $it;
9
10// Callback
11$it2 = new CallbackFilterIterator($it, function($elem) use(&$it2) {
12    return true;
13});
14
15// Callback object
16new class {
17    public function __construct() {
18        $it = new ArrayIterator([1, 2, 3]);
19        $this->it = new CallbackFilterIterator($it, function($elem) {
20            return true;
21        });
22    }
23};
24
25// Recursive callback
26$it = new RecursiveArrayIterator([1, 2, 3]);
27$it2 = new RecursiveCallbackFilterIterator($it, function($elem) use(&$it2) {
28    return true;
29});
30
31// Cache
32$it = new ArrayIterator();
33$it2 = new CachingIterator($it, CachingIterator::FULL_CACHE);
34$it2['x'] = $it2;
35$it2->next();
36
37// Recursive cache
38$it = new RecursiveArrayIterator();
39$it2 = new RecursiveCachingIterator($it, CachingIterator::FULL_CACHE);
40$it2['x'] = $it2;
41$it2->next();
42
43// Append
44$it = new ArrayIterator();
45$it2 = new AppendIterator();
46$it[] = $it2;
47$it2->append($it);
48
49// Recursive iterator
50$it = new RecursiveArrayIterator([1, 2, 3]);
51$it2 = new RecursiveIteratorIterator($it);
52$it[] = $it2;
53
54// Recursive iterator at level>0.
55$it = new RecursiveArrayIterator([[1]]);
56$it2 = new RecursiveIteratorIterator($it);
57$it[] = $it2;
58$it2->next();
59
60?>
61===DONE===
62--EXPECT--
63===DONE===
64