xref: /PHP-8.1/ext/spl/tests/array_007.phpt (revision 75a678a7)
1--TEST--
2SPL: ArrayObject/Iterator from IteratorAggregate
3--FILE--
4<?php
5
6// This test also needs to exclude the protected and private variables
7// since they cannot be accessed from the external object which iterates
8// them.
9
10class test implements IteratorAggregate
11{
12    public    $pub = "public";
13    protected $pro = "protected";
14    private   $pri = "private";
15
16    function __construct()
17    {
18        $this->imp = "implicit";
19    }
20
21    function getIterator(): Traversable
22    {
23        $it = new ArrayObject($this);
24        return $it->getIterator();
25    }
26};
27
28$test = new test;
29$test->dyn = "dynamic";
30
31print_r($test);
32
33print_r($test->getIterator());
34
35foreach($test as $key => $val)
36{
37    echo "$key => $val\n";
38}
39
40?>
41--EXPECT--
42test Object
43(
44    [pub] => public
45    [pro:protected] => protected
46    [pri:test:private] => private
47    [imp] => implicit
48    [dyn] => dynamic
49)
50ArrayIterator Object
51(
52    [storage:ArrayIterator:private] => ArrayObject Object
53        (
54            [storage:ArrayObject:private] => test Object
55                (
56                    [pub] => public
57                    [pro:protected] => protected
58                    [pri:test:private] => private
59                    [imp] => implicit
60                    [dyn] => dynamic
61                )
62
63        )
64
65)
66pub => public
67imp => implicit
68dyn => dynamic
69