xref: /PHP-8.3/Zend/tests/gh7958.phpt (revision fb70460d)
1--TEST--
2GH-7958 (Nested CallbackFilterIterator is leaking memory)
3--FILE--
4<?php
5class Action
6{
7    public \Iterator $iterator;
8
9    public function __construct(array $data)
10    {
11        $this->iterator = new ArrayIterator($data);
12        echo '-- c ' . spl_object_id($this) . "\n";
13    }
14
15    public function __destruct()
16    {
17        echo '-- d ' . spl_object_id($this) . "\n";
18    }
19
20    public function filter()
21    {
22        $this->iterator = new \CallbackFilterIterator($this->iterator, fn() => true);
23        $this->iterator->rewind();
24    }
25}
26
27$action = new Action(['a', 'b']);
28$action->filter();
29$action->filter();
30print_r(iterator_to_array($action->iterator));
31$action = null;
32gc_collect_cycles();
33echo "==DONE==\n";
34?>
35--EXPECT--
36-- c 1
37Array
38(
39    [0] => a
40    [1] => b
41)
42-- d 1
43==DONE==
44