xref: /PHP-5.3/ext/spl/tests/bug45614.phpt (revision f9ef6c87)
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}
12
13function showFirstTwoItems($it) {
14  echo str_replace("\0", '\0', $it->key()) . " => " . $it->current() .
15"\n";
16  $it->next();
17  echo str_replace("\0", '\0', $it->key()) . " => " . $it->current() .
18"\n";
19}
20
21$ao = new ArrayObject(new C);
22$ai = $ao->getIterator();
23
24echo "--> Show the first two items:\n";
25showFirstTwoItems($ai);
26
27echo "\n--> Rewind and show the first two items:\n";
28$ai->rewind();
29showFirstTwoItems($ai);
30
31echo "\n--> Invalidate current position and show the first two items:\n";
32unset($ai[$ai->key()]);
33$ai->current();
34showFirstTwoItems($ai);
35
36echo "\n--> Rewind, seek and show the first two items:\n";
37$ai->rewind();
38$ai->seek(0);
39showFirstTwoItems($ai);
40?>
41--EXPECT--
42--> Show the first two items:
43pub1 => public1
44pub2 => public2
45
46--> Rewind and show the first two items:
47pub1 => public1
48pub2 => public2
49
50--> Invalidate current position and show the first two items:
51pub1 => public1
52pub3 => public3
53
54--> Rewind, seek and show the first two items:
55pub1 => public1
56pub3 => public3
57