- Update tests to reflect current situation

# I don't feel like discussing this issue anymore - maybe we need to find
# a way of returning proxies to get the requested behavior back - i'll give
# it a try for PHP 5.2. So long we'll have to stay with the original
# decision that we don't support references at all with ArrayAccess.
This commit is contained in:
Marcus Boerger 2005-06-19 20:49:17 +00:00
parent 21ce9394a7
commit f01c842ef6
3 changed files with 30 additions and 18 deletions

View file

@ -12,7 +12,7 @@ class object implements ArrayAccess {
echo __METHOD__ . "($index)\n"; echo __METHOD__ . "($index)\n";
return array_key_exists($index, $this->a); return array_key_exists($index, $this->a);
} }
function &offsetGet($index) { function offsetGet($index) {
echo __METHOD__ . "($index)\n"; echo __METHOD__ . "($index)\n";
switch($index) { switch($index) {
case 1: case 1:
@ -48,12 +48,9 @@ var_dump($obj[2]);
===DONE=== ===DONE===
--EXPECTF-- --EXPECTF--
object::offsetGet(1) object::offsetGet(1)
Strict Standards: Only variable references should be returned by reference in %sarray_access_003.php on line %d
string(6) "fooBar" string(6) "fooBar"
object::offsetGet(2) object::offsetGet(2)
int(1) int(1)
object::offsetGet(2) object::offsetGet(2)
object::offsetGet(2)
int(2) Fatal error: Objects used as arrays in post/pre increment/decrement must return values by reference in %sarray_access_003.php on line %d
===DONE===

View file

@ -14,7 +14,7 @@ class Peoples implements ArrayAccess {
return array_key_exists($this->person, $index); return array_key_exists($this->person, $index);
} }
function &offsetGet($index) { function offsetGet($index) {
return $this->person[$index]; return $this->person[$index];
} }
@ -39,20 +39,34 @@ echo "---ArrayOverloading---\n";
$people = new Peoples; $people = new Peoples;
var_dump($people[0]);
var_dump($people[0]['name']); var_dump($people[0]['name']);
$people[0]['name'] = $people->person[0]['name'] . 'Foo'; var_dump($people->person[0]['name'] . 'Foo'); // impossible to assign this since we don't return references here
$x = $people[0]; // creates a copy
$x['name'] .= 'Foo';
$people[0] = $x;
var_dump($people[0]);
$people[0]['name'] = 'JoeFoo';
var_dump($people[0]['name']); var_dump($people[0]['name']);
$people[0]['name'] .= 'Bar'; $people[0]['name'] = 'JoeFooBar';
var_dump($people[0]['name']); var_dump($people[0]['name']);
echo "---Done---\n";
?> ?>
--EXPECT-- ===DONE===
--EXPECTF--
string(3) "Joe" string(3) "Joe"
string(6) "JoeFoo" string(6) "JoeFoo"
string(9) "JoeFooBar" string(9) "JoeFooBar"
---ArrayOverloading--- ---ArrayOverloading---
array(1) {
["name"]=>
string(3) "Joe"
}
string(3) "Joe" string(3) "Joe"
string(6) "JoeFoo" string(6) "JoeFoo"
string(9) "JoeFooBar" array(1) {
---Done--- ["name"]=>
string(6) "JoeFoo"
}
Fatal error: Objects used as arrays in post/pre increment/decrement must return values by reference in %sarray_access_005.php on line %d

View file

@ -14,7 +14,7 @@ class Peoples implements ArrayAccess {
return array_key_exists($this->person, $index); return array_key_exists($this->person, $index);
} }
function & offsetGet($index) { function offsetGet($index) {
return $this->person[$index]; return $this->person[$index];
} }
@ -39,6 +39,8 @@ echo "===ArrayOverloading===\n";
$people = new Peoples; $people = new Peoples;
var_dump($people[0]['name']);
$people[0]['name'] = 'FooBar';
var_dump($people[0]['name']); var_dump($people[0]['name']);
$people[0]['name'] = $people->person[0]['name'] . 'Bar'; $people[0]['name'] = $people->person[0]['name'] . 'Bar';
var_dump($people[0]['name']); var_dump($people[0]['name']);
@ -47,12 +49,11 @@ var_dump($people[0]['name']);
?> ?>
===DONE=== ===DONE===
--EXPECT-- --EXPECTF--
string(3) "Foo" string(3) "Foo"
string(6) "FooBar" string(6) "FooBar"
string(9) "FooBarBaz" string(9) "FooBarBaz"
===ArrayOverloading=== ===ArrayOverloading===
string(3) "Foo" string(3) "Foo"
string(6) "FooBar"
string(9) "FooBarBaz" Fatal error: Objects used as arrays in post/pre increment/decrement must return values by reference in %sarray_access_008.php on line %d
===DONE===