xref: /PHP-7.3/ext/spl/tests/bug61527.phpt (revision ded3d984)
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--EXPECT--
68NULL
69NULL
70int(4)
71int(5)
72NULL
73NULL
74NULL
75NULL
76NULL
77NULL
78NULL
79bool(false)
80bool(false)
81NULL
82==DONE==
83