summaryrefslogtreecommitdiff
path: root/ext/spl/tests/array_008.phpt
blob: 883a35873dbfec247bc28cedb8e88b50d0b043eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
--TEST--
SPL: ArrayIterator and foreach reference
--SKIPIF--
<?php if (!extension_loaded("spl")) print "skip"; ?>
--INI--
error_reporting=2047
--FILE--
<?php

echo "==Normal==\n";

$arr = array(0=>0, 1=>1, 2=>2);
$obj = new ArrayObject($arr);

foreach($obj as $ak=>&$av) {
	foreach($obj as $bk=>&$bv) {
		if ($ak==0 && $bk==0) {
			$bv = "modify";
		}
		echo "$ak=>$av - $bk=>$bv\n";
	}
}

echo "==UseRef==\n";

$arr = array(0=>0, 1=>1, 2=>2);
$obj = new ArrayObject(&$arr);

foreach($obj as $ak=>&$av) {
	foreach($obj as $bk=>&$bv) {
		if ($ak==0 && $bk==0) {
			$bv = "modify";
		}
		echo "$ak=>$av - $bk=>$bv\n";
	}
}

?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
==Normal==
0=>modify - 0=>modify
0=>modify - 1=>1
0=>modify - 2=>2
1=>1 - 0=>modify
1=>1 - 1=>1
1=>1 - 2=>2
2=>2 - 0=>modify
2=>2 - 1=>1
2=>2 - 2=>2
==UseRef==
0=>modify - 0=>modify
0=>modify - 1=>1
0=>modify - 2=>2
1=>1 - 0=>modify
1=>1 - 1=>1
1=>1 - 2=>2
2=>2 - 0=>modify
2=>2 - 1=>1
2=>2 - 2=>2
===DONE===