File tree Expand file tree Collapse file tree 1 file changed +55
-4
lines changed
Expand file tree Collapse file tree 1 file changed +55
-4
lines changed Original file line number Diff line number Diff line change @@ -12,22 +12,73 @@ $box = new Box();
1212$ box ->value = 1 ;
1313$ copy = $ box ;
1414
15+ echo "Iteration by value \n" ;
16+
1517foreach ($ box as $ value ) {
1618 var_dump ($ value );
1719}
1820
21+ echo "\nIteration by ref \n" ;
22+
1923foreach ($ 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
2961int(1)
30- string(5) "value"
62+
63+ Iteration by ref
3164int(2)
32- string(7) "dynamic"
3365int(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+ }
You can’t perform that action at this time.
0 commit comments