xref: /PHP-8.1/ext/spl/tests/iterator_046.phpt (revision f8d79582)
1--TEST--
2SPL: CachingIterator and __toString using bypassed string keys
3--FILE--
4<?php
5
6class MyFoo
7{
8    function __toString()
9    {
10        return 'foo';
11    }
12}
13
14class MyCachingIterator extends CachingIterator
15{
16    function __construct(Iterator $it, $flags = 0)
17    {
18        parent::__construct($it, $flags);
19    }
20
21    function fill()
22    {
23        echo __METHOD__ . "()\n";
24        foreach($this as $v) ;
25    }
26
27    function show()
28    {
29        echo __METHOD__ . "()\n";
30        foreach($this as $v)
31        {
32            var_dump((string)$this);
33        }
34    }
35}
36
37$it = new MyCachingIterator(new ArrayIterator(array(0, 'foo'=>1, 'bar'=>2)), CachingIterator::TOSTRING_USE_KEY);
38
39$it->fill();
40$it->show();
41
42?>
43--EXPECT--
44MyCachingIterator::fill()
45MyCachingIterator::show()
46string(1) "0"
47string(3) "foo"
48string(3) "bar"
49