xref: /PHP-5.3/ext/spl/tests/array_015.phpt (revision 610c7fbe)
1--TEST--
2SPL: ArrayIterator::next() with internal arrays
3--FILE--
4<?php
5
6$ar = new ArrayObject();
7
8$ar[0] = 1;
9$ar[1] = 2;
10$ar[2] = 3;
11$ar[3] = 4;
12$ar[4] = 5;
13
14var_dump($ar);
15
16$it = $ar->getIterator();
17
18$ar->offsetUnset($it->key());
19$it->next();
20
21var_dump($it->current());
22var_dump($ar);
23
24foreach($it as $k => $v)
25{
26	$ar->offsetUnset($k+1);
27	echo "$k=>$v\n";
28}
29
30var_dump($ar);
31
32foreach($it as $k => $v)
33{
34	$ar->offsetUnset($k);
35	echo "$k=>$v\n";
36}
37
38var_dump($ar);
39
40?>
41===DONE===
42<?php exit(0); ?>
43--EXPECTF--
44object(ArrayObject)#%d (1) {
45  %s"storage"%s"ArrayObject":private]=>
46  array(5) {
47    [0]=>
48    int(1)
49    [1]=>
50    int(2)
51    [2]=>
52    int(3)
53    [3]=>
54    int(4)
55    [4]=>
56    int(5)
57  }
58}
59
60Notice: ArrayIterator::next(): Array was modified outside object and internal position is no longer valid in %sarray_015.php on line %d
61int(2)
62object(ArrayObject)#%d (1) {
63  %s"storage"%s"ArrayObject":private]=>
64  array(4) {
65    [1]=>
66    int(2)
67    [2]=>
68    int(3)
69    [3]=>
70    int(4)
71    [4]=>
72    int(5)
73  }
74}
751=>2
763=>4
77object(ArrayObject)#%d (1) {
78  %s"storage"%s"ArrayObject":private]=>
79  array(2) {
80    [1]=>
81    int(2)
82    [3]=>
83    int(4)
84  }
85}
861=>2
87
88Notice: main(): ArrayIterator::next(): Array was modified outside object and internal position is no longer valid in %sarray_015.php on line %d
893=>4
90
91Notice: main(): ArrayIterator::next(): Array was modified outside object and internal position is no longer valid in %sarray_015.php on line %d
92object(ArrayObject)#%d (1) {
93  %s"storage"%s"ArrayObject":private]=>
94  array(0) {
95  }
96}
97===DONE===
98