xref: /PHP-5.4/ext/spl/tests/bug61527.phpt (revision a5d45bae)
1--TEST--
2Bug #61527 (Recursive/ArrayIterator gives misleading notice when array empty or moved to the end)
3--FILE--
4<?php
5$ao = new ArrayObject(array());
6$ai = $ao->getIterator();
7
8/* testing empty array, should no notice at all */
9$ai->next();
10var_dump($ai->key());
11var_dump($ai->current());
12
13/* testing array changing */
14$ao2 = new ArrayObject(array(1 => 1, 2, 3, 4, 5));
15$ai2 = $ao2->getIterator();
16
17$ao2->offsetUnset($ai2->key());
18$ai2->next();
19
20/* now point to 2 */
21$ao2->offsetUnset($ai2->key());
22var_dump($ai2->key());
23
24/* now point to 3 */
25$ao2->offsetUnset($ai2->key());
26var_dump($ai2->current());
27
28$ai2->next();
29var_dump($ai2->key());
30var_dump($ai2->current());
31
32/* should be at the end and no notice */
33$ai2->next();
34var_dump($ai2->key());
35var_dump($ai2->current());
36
37$ai2->rewind();
38$ai2->next();
39$ai2->next();
40/* should reached the end */
41var_dump($ai2->next());
42var_dump($ai2->key());
43
44/* testing RecursiveArrayIterator */
45$ao3 = new ArrayObject(array(), NULL, 'RecursiveArrayIterator');
46$ai3 = $ao3->getIterator();
47
48var_dump($ai3->getChildren());
49
50$ao4 = new ArrayObject(array(1, 2), NULL, 'RecursiveArrayIterator');
51$ai4 = $ao4->getIterator();
52
53$ai4->next();
54$ai4->next();
55$ai4->next();
56var_dump($ai4->hasChildren());
57
58$ai4->rewind();
59$ao4->offsetUnset($ai4->key());
60var_dump($ai4->hasChildren());
61
62$ao4->offsetUnset($ai4->key());
63var_dump($ai4->getChildren());
64?>
65==DONE==
66<?php exit(0); ?>
67--EXPECTF--
68NULL
69NULL
70
71Notice: ArrayIterator::next(): Array was modified outside object and internal position is no longer valid in %sbug61527.php on line %d
72
73Notice: ArrayIterator::key(): Array was modified outside object and internal position is no longer valid in %sbug61527.php on line %d
74NULL
75
76Notice: ArrayIterator::current(): Array was modified outside object and internal position is no longer valid in %sbug61527.php on line %d
77NULL
78int(5)
79int(5)
80NULL
81NULL
82NULL
83NULL
84NULL
85bool(false)
86
87Notice: RecursiveArrayIterator::hasChildren(): Array was modified outside object and internal position is no longer valid in %sbug61527.php on line %d
88bool(false)
89
90Notice: RecursiveArrayIterator::getChildren(): Array was modified outside object and internal position is no longer valid in %sbug61527.php on line %d
91NULL
92==DONE==
93