xref: /PHP-5.5/ext/spl/tests/array_007.phpt (revision 610c7fbe)
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()
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===DONE===
42<?php exit(0); ?>
43--EXPECTF--
44test Object
45(
46    [pub] => public
47    [pro:protected] => protected
48    [pri:test:private] => private
49    [imp] => implicit
50    [dyn] => dynamic
51)
52ArrayIterator Object
53(
54    [storage:ArrayIterator:private] => ArrayObject Object
55        (
56            [storage:ArrayObject:private] => test Object
57                (
58                    [pub] => public
59                    [pro:protected] => protected
60                    [pri:test:private] => private
61                    [imp] => implicit
62                    [dyn] => dynamic
63                )
64
65        )
66
67)
68pub => public
69imp => implicit
70dyn => dynamic
71===DONE===
72