xref: /PHP-8.2/ext/spl/tests/bug65387.phpt (revision 902d6439)
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    private $it;
18    public function __construct() {
19        $it = new ArrayIterator([1, 2, 3]);
20        $this->it = new CallbackFilterIterator($it, function($elem) {
21            return true;
22        });
23    }
24};
25
26// Recursive callback
27$it = new RecursiveArrayIterator([1, 2, 3]);
28$it2 = new RecursiveCallbackFilterIterator($it, function($elem) use(&$it2) {
29    return true;
30});
31
32// Cache
33$it = new ArrayIterator();
34$it2 = new CachingIterator($it, CachingIterator::FULL_CACHE);
35$it2['x'] = $it2;
36$it2->next();
37
38// Recursive cache
39$it = new RecursiveArrayIterator();
40$it2 = new RecursiveCachingIterator($it, CachingIterator::FULL_CACHE);
41$it2['x'] = $it2;
42$it2->next();
43
44// Append
45$it = new ArrayIterator();
46$it2 = new AppendIterator();
47$it[] = $it2;
48$it2->append($it);
49
50// Recursive iterator
51$it = new RecursiveArrayIterator([1, 2, 3]);
52$it2 = new RecursiveIteratorIterator($it);
53$it[] = $it2;
54
55// Recursive iterator at level>0.
56$it = new RecursiveArrayIterator([[1]]);
57$it2 = new RecursiveIteratorIterator($it);
58$it[] = $it2;
59$it2->next();
60
61?>
62===DONE===
63--EXPECT--
64===DONE===
65