xref: /PHP-5.6/ext/spl/tests/iterator_044.phpt (revision 610c7fbe)
1--TEST--
2SPL: CachingIterator and offsetGet/Exists using flag FULL_CACHE
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 test($ar)
22	{
23		foreach($ar as $k => $v)
24		{
25			echo "===$k===\n";
26			var_dump($v);
27			var_dump($this->offsetExists($v));
28			var_dump($this->offsetGet($v));
29		}
30	}
31}
32
33$it = new MyCachingIterator(new ArrayIterator(array(0, 'foo'=>1, 2, 'bar'=>3, 4)));
34
35try
36{
37	var_dump($it->offsetExists(0));
38}
39catch(Exception $e)
40{
41	echo "Exception: " . $e->getMessage() . "\n";
42}
43
44try
45{
46	var_dump($it->offsetGet(0));
47}
48catch(Exception $e)
49{
50	echo "Exception: " . $e->getMessage() . "\n";
51}
52
53$it = new MyCachingIterator(new ArrayIterator(array(0, 'foo'=>1, 2, 'bar'=>3, 4)), CachingIterator::FULL_CACHE);
54
55var_dump($it->offsetExists());
56var_dump($it->offsetGet());
57
58$checks = array(0, new stdClass, new MyFoo, NULL, 2, 'foo', 3);
59
60$it->test($checks);
61
62echo "===FILL===\n";
63
64foreach($it as $v); // read all into cache
65
66$it->test($checks);
67
68?>
69===DONE===
70<?php exit(0); ?>
71--EXPECTF--
72Exception: MyCachingIterator does not use a full cache (see CachingIterator::__construct)
73Exception: MyCachingIterator does not use a full cache (see CachingIterator::__construct)
74
75Warning: CachingIterator::offsetExists() expects exactly 1 parameter, 0 given in %siterator_044.php on line %d
76NULL
77
78Warning: CachingIterator::offsetGet() expects exactly 1 parameter, 0 given in %siterator_044.php on line %d
79NULL
80===0===
81int(0)
82bool(false)
83
84Notice: Undefined index: 0 in %siterator_044.php on line %d
85NULL
86===1===
87object(stdClass)#%d (0) {
88}
89
90Warning: CachingIterator::offsetExists() expects parameter 1 to be string, object given in %siterator_044.php on line %d
91NULL
92
93Warning: CachingIterator::offsetGet() expects parameter 1 to be string, object given in %siterator_044.php on line %d
94NULL
95===2===
96object(MyFoo)#%d (0) {
97}
98bool(false)
99
100Notice: Undefined index: foo in %siterator_044.php on line %d
101NULL
102===3===
103NULL
104bool(false)
105
106Notice: Undefined index:  in %siterator_044.php on line %d
107NULL
108===4===
109int(2)
110bool(false)
111
112Notice: Undefined index: 2 in %siterator_044.php on line %d
113NULL
114===5===
115string(3) "foo"
116bool(false)
117
118Notice: Undefined index: foo in %siterator_044.php on line %d
119NULL
120===6===
121int(3)
122bool(false)
123
124Notice: Undefined index: 3 in %siterator_044.php on line %d
125NULL
126===FILL===
127===0===
128int(0)
129bool(true)
130int(0)
131===1===
132object(stdClass)#1 (0) {
133}
134
135Warning: CachingIterator::offsetExists() expects parameter 1 to be string, object given in %siterator_044.php on line %d
136NULL
137
138Warning: CachingIterator::offsetGet() expects parameter 1 to be string, object given in %siterator_044.php on line %d
139NULL
140===2===
141object(MyFoo)#2 (0) {
142}
143bool(true)
144int(1)
145===3===
146NULL
147bool(false)
148
149Notice: Undefined index:  in %siterator_044.php on line %d
150NULL
151===4===
152int(2)
153bool(true)
154int(4)
155===5===
156string(3) "foo"
157bool(true)
158int(1)
159===6===
160int(3)
161bool(false)
162
163Notice: Undefined index: 3 in %siterator_044.php on line %d
164NULL
165===DONE===
166