2003-12-17 22:14:59 +00:00
|
|
|
--TEST--
|
|
|
|
ZE2 ArrayAccess and sub Arrays
|
|
|
|
--FILE--
|
|
|
|
<?php
|
|
|
|
|
|
|
|
class Peoples implements ArrayAccess {
|
|
|
|
public $person;
|
|
|
|
|
|
|
|
function __construct() {
|
|
|
|
$this->person = array(array('name'=>'Joe'));
|
|
|
|
}
|
|
|
|
|
|
|
|
function offsetExists($index) {
|
|
|
|
return array_key_exists($this->person, $index);
|
|
|
|
}
|
|
|
|
|
2005-06-19 20:49:17 +00:00
|
|
|
function offsetGet($index) {
|
2003-12-17 22:14:59 +00:00
|
|
|
return $this->person[$index];
|
|
|
|
}
|
|
|
|
|
|
|
|
function offsetSet($index, $value) {
|
|
|
|
$this->person[$index] = $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
function offsetUnset($index) {
|
|
|
|
unset($this->person[$index]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$people = new Peoples;
|
|
|
|
|
|
|
|
var_dump($people->person[0]['name']);
|
|
|
|
$people->person[0]['name'] = $people->person[0]['name'] . 'Foo';
|
|
|
|
var_dump($people->person[0]['name']);
|
|
|
|
$people->person[0]['name'] .= 'Bar';
|
|
|
|
var_dump($people->person[0]['name']);
|
|
|
|
|
|
|
|
echo "---ArrayOverloading---\n";
|
|
|
|
|
|
|
|
$people = new Peoples;
|
|
|
|
|
2005-06-19 20:49:17 +00:00
|
|
|
var_dump($people[0]);
|
2003-12-17 22:14:59 +00:00
|
|
|
var_dump($people[0]['name']);
|
2005-06-19 20:49:17 +00:00
|
|
|
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';
|
2003-12-17 22:14:59 +00:00
|
|
|
var_dump($people[0]['name']);
|
2005-06-19 20:49:17 +00:00
|
|
|
$people[0]['name'] = 'JoeFooBar';
|
2003-12-17 22:14:59 +00:00
|
|
|
var_dump($people[0]['name']);
|
|
|
|
|
|
|
|
?>
|
2005-06-19 20:49:17 +00:00
|
|
|
===DONE===
|
|
|
|
--EXPECTF--
|
2003-12-17 22:14:59 +00:00
|
|
|
string(3) "Joe"
|
2003-12-19 10:23:05 +00:00
|
|
|
string(6) "JoeFoo"
|
|
|
|
string(9) "JoeFooBar"
|
2003-12-17 22:14:59 +00:00
|
|
|
---ArrayOverloading---
|
2005-06-19 20:49:17 +00:00
|
|
|
array(1) {
|
|
|
|
["name"]=>
|
|
|
|
string(3) "Joe"
|
|
|
|
}
|
2003-12-17 22:14:59 +00:00
|
|
|
string(3) "Joe"
|
2003-12-19 10:23:05 +00:00
|
|
|
string(6) "JoeFoo"
|
2005-06-19 20:49:17 +00:00
|
|
|
array(1) {
|
|
|
|
["name"]=>
|
|
|
|
string(6) "JoeFoo"
|
|
|
|
}
|
|
|
|
|
2006-11-10 14:20:26 +00:00
|
|
|
Notice: Indirect modification of overloaded element of Peoples has no effect in /home/dmitry/php/php5.2/tests/classes/array_access_005.php on line 46
|
|
|
|
|
2005-06-19 20:49:17 +00:00
|
|
|
Fatal error: Objects used as arrays in post/pre increment/decrement must return values by reference in %sarray_access_005.php on line %d
|