xref: /PHP-5.3/ext/spl/tests/array_008.phpt (revision 610c7fbe)
1--TEST--
2SPL: ArrayIterator and foreach reference
3--INI--
4allow_call_time_pass_reference=1
5--FILE--
6<?php
7
8echo "==Normal==\n";
9
10$arr = array(0=>0, 1=>1, 2=>2);
11$obj = new ArrayObject($arr);
12
13foreach($obj as $ak=>&$av) {
14	foreach($obj as $bk=>&$bv) {
15		if ($ak==0 && $bk==0) {
16			$bv = "modify";
17		}
18		echo "$ak=>$av - $bk=>$bv\n";
19	}
20}
21
22echo "==UseRef==\n";
23
24$arr = array(0=>0, 1=>1, 2=>2);
25$obj = new ArrayObject(&$arr);
26
27foreach($obj as $ak=>&$av) {
28	foreach($obj as $bk=>&$bv) {
29		if ($ak==0 && $bk==0) {
30			$bv = "modify";
31		}
32		echo "$ak=>$av - $bk=>$bv\n";
33	}
34}
35
36?>
37===DONE===
38<?php exit(0); ?>
39--EXPECTF--
40==Normal==
410=>modify - 0=>modify
420=>modify - 1=>1
430=>modify - 2=>2
441=>1 - 0=>modify
451=>1 - 1=>1
461=>1 - 2=>2
472=>2 - 0=>modify
482=>2 - 1=>1
492=>2 - 2=>2
50==UseRef==
510=>modify - 0=>modify
520=>modify - 1=>1
530=>modify - 2=>2
541=>1 - 0=>modify
551=>1 - 1=>1
561=>1 - 2=>2
572=>2 - 0=>modify
582=>2 - 1=>1
592=>2 - 2=>2
60===DONE===
61