File tree Expand file tree Collapse file tree 3 files changed +30
-18
lines changed
Expand file tree Collapse file tree 3 files changed +30
-18
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ class object implements ArrayAccess {
1212 echo __METHOD__ . "( $ index) \n" ;
1313 return array_key_exists ($ index , $ this ->a );
1414 }
15- function & offsetGet ($ index ) {
15+ function offsetGet ($ index ) {
1616 echo __METHOD__ . "( $ index) \n" ;
1717 switch ($ index ) {
1818 case 1 :
@@ -48,12 +48,9 @@ var_dump($obj[2]);
4848===DONE===
4949--EXPECTF--
5050object::offsetGet(1)
51-
52- Strict Standards: Only variable references should be returned by reference in %sarray_access_003.php on line %d
5351string(6) "fooBar"
5452object::offsetGet(2)
5553int(1)
5654object::offsetGet(2)
57- object::offsetGet(2)
58- int(2)
59- ===DONE===
55+
56+ Fatal error: Objects used as arrays in post/pre increment/decrement must return values by reference in %sarray_access_003.php on line %d
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ class Peoples implements ArrayAccess {
1414 return array_key_exists ($ this ->person , $ index );
1515 }
1616
17- function & offsetGet ($ index ) {
17+ function offsetGet ($ index ) {
1818 return $ this ->person [$ index ];
1919 }
2020
@@ -39,20 +39,34 @@ echo "---ArrayOverloading---\n";
3939
4040$ people = new Peoples ;
4141
42+ var_dump ($ people [0 ]);
4243var_dump ($ people [0 ]['name ' ]);
43- $ people [0 ]['name ' ] = $ people ->person [0 ]['name ' ] . 'Foo ' ;
44+ var_dump ($ people ->person [0 ]['name ' ] . 'Foo ' ); // impossible to assign this since we don't return references here
45+ $ x = $ people [0 ]; // creates a copy
46+ $ x ['name ' ] .= 'Foo ' ;
47+ $ people [0 ] = $ x ;
48+ var_dump ($ people [0 ]);
49+ $ people [0 ]['name ' ] = 'JoeFoo ' ;
4450var_dump ($ people [0 ]['name ' ]);
45- $ people [0 ]['name ' ] . = 'Bar ' ;
51+ $ people [0 ]['name ' ] = 'JoeFooBar ' ;
4652var_dump ($ people [0 ]['name ' ]);
4753
48- echo "---Done--- \n" ;
4954?>
50- --EXPECT--
55+ ===DONE===
56+ --EXPECTF--
5157string(3) "Joe"
5258string(6) "JoeFoo"
5359string(9) "JoeFooBar"
5460---ArrayOverloading---
61+ array(1) {
62+ ["name"]=>
63+ string(3) "Joe"
64+ }
5565string(3) "Joe"
5666string(6) "JoeFoo"
57- string(9) "JoeFooBar"
58- ---Done---
67+ array(1) {
68+ ["name"]=>
69+ string(6) "JoeFoo"
70+ }
71+
72+ Fatal error: Objects used as arrays in post/pre increment/decrement must return values by reference in %sarray_access_005.php on line %d
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ class Peoples implements ArrayAccess {
1414 return array_key_exists ($ this ->person , $ index );
1515 }
1616
17- function & offsetGet ($ index ) {
17+ function offsetGet ($ index ) {
1818 return $ this ->person [$ index ];
1919 }
2020
@@ -39,6 +39,8 @@ echo "===ArrayOverloading===\n";
3939
4040$ people = new Peoples ;
4141
42+ var_dump ($ people [0 ]['name ' ]);
43+ $ people [0 ]['name ' ] = 'FooBar ' ;
4244var_dump ($ people [0 ]['name ' ]);
4345$ people [0 ]['name ' ] = $ people ->person [0 ]['name ' ] . 'Bar ' ;
4446var_dump ($ people [0 ]['name ' ]);
@@ -47,12 +49,11 @@ var_dump($people[0]['name']);
4749
4850?>
4951===DONE===
50- --EXPECT --
52+ --EXPECTF --
5153string(3) "Foo"
5254string(6) "FooBar"
5355string(9) "FooBarBaz"
5456===ArrayOverloading===
5557string(3) "Foo"
56- string(6) "FooBar"
57- string(9) "FooBarBaz"
58- ===DONE===
58+
59+ Fatal error: Objects used as arrays in post/pre increment/decrement must return values by reference in %sarray_access_008.php on line %d
You can’t perform that action at this time.
0 commit comments