xref: /PHP-8.3/ext/spl/tests/bug45614.phpt (revision f8d79582)
1--TEST--
2SPL: Bug#45614 (ArrayIterator can show 1st private prop of wrapped object)
3--FILE--
4<?php
5class C {
6    private $priv1 = 'secret1';
7    private $priv2 = 'secret2';
8    public $pub1 = 'public1';
9    public $pub2 = 'public2';
10    public $pub3 = 'public3';
11    public $pub4 = 'public4';
12}
13
14function showFirstTwoItems($it) {
15  echo str_replace("\0", '\0', $it->key()) . " => " . $it->current() .
16"\n";
17  $it->next();
18  echo str_replace("\0", '\0', $it->key()) . " => " . $it->current() .
19"\n";
20}
21
22$ao = new ArrayObject(new C);
23$ai = $ao->getIterator();
24
25echo "--> Show the first two items:\n";
26showFirstTwoItems($ai);
27
28echo "\n--> Rewind and show the first two items:\n";
29$ai->rewind();
30showFirstTwoItems($ai);
31
32echo "\n--> Invalidate current position and show the first two items:\n";
33unset($ai[$ai->key()]);
34$ai->current();
35showFirstTwoItems($ai);
36
37echo "\n--> Rewind, seek and show the first two items:\n";
38$ai->rewind();
39$ai->seek(0);
40showFirstTwoItems($ai);
41?>
42--EXPECT--
43--> Show the first two items:
44pub1 => public1
45pub2 => public2
46
47--> Rewind and show the first two items:
48pub1 => public1
49pub2 => public2
50
51--> Invalidate current position and show the first two items:
52pub3 => public3
53pub4 => public4
54
55--> Rewind, seek and show the first two items:
56pub1 => public1
57pub3 => public3
58