Skip to content

Commit 59f1896

Browse files
committed
Improve iter tests
1 parent ca5b8ea commit 59f1896

File tree

1 file changed

+55
-4
lines changed

1 file changed

+55
-4
lines changed

Zend/tests/data_classes/iter.phpt

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,73 @@ $box = new Box();
1212
$box->value = 1;
1313
$copy = $box;
1414

15+
echo "Iteration by value\n";
16+
1517
foreach ($box as $value) {
1618
var_dump($value);
1719
}
1820

21+
echo "\nIteration by ref\n";
22+
1923
foreach ($box as $prop => &$value) {
20-
if ($box->value === 1) {
24+
if ($prop === 'value' && $value === 1) {
2125
$box->dynamic = 1;
2226
}
2327
$value++;
24-
var_dump($prop, $value);
28+
var_dump($value);
2529
}
2630

31+
echo "\nIteration by ref on copy\n";
32+
33+
$copy2 = $copy;
34+
$copy2Ref = &$copy2;
35+
36+
foreach ($copy2Ref as $prop => &$value) {
37+
$value++;
38+
var_dump($value);
39+
}
40+
41+
echo "\nIteration by ref on ref with separation\n";
42+
43+
function &getBox() {
44+
global $box;
45+
$box2 = $box;
46+
return $box2;
47+
}
48+
49+
foreach (getBox() as $prop => &$value) {
50+
$value++;
51+
var_dump($value);
52+
}
53+
54+
echo "\nDone\n";
55+
56+
var_dump($box, $copy);
57+
2758
?>
2859
--EXPECT--
60+
Iteration by value
2961
int(1)
30-
string(5) "value"
62+
63+
Iteration by ref
3164
int(2)
32-
string(7) "dynamic"
3365
int(2)
66+
67+
Iteration by ref on copy
68+
int(2)
69+
70+
Iteration by ref on ref with separation
71+
int(3)
72+
int(3)
73+
74+
Done
75+
object(Box)#2 (2) {
76+
["value"]=>
77+
int(2)
78+
["dynamic"]=>
79+
int(2)
80+
}
81+
object(Box)#1 (1) {
82+
["value"]=>
83+
int(1)
84+
}

0 commit comments

Comments
 (0)