1--TEST--
2ZE2 ArrayAccess and sub Arrays
3--FILE--
4<?php
5
6class Peoples implements ArrayAccess {
7	public $person;
8
9	function __construct() {
10		$this->person = array(array('name'=>'Joe'));
11	}
12
13	function offsetExists($index) {
14		return array_key_exists($this->person, $index);
15	}
16
17	function offsetGet($index) {
18		return $this->person[$index];
19	}
20
21	function offsetSet($index, $value) {
22		$this->person[$index] = $value;
23	}
24
25	function offsetUnset($index) {
26		unset($this->person[$index]);
27	}
28}
29
30$people = new Peoples;
31
32var_dump($people->person[0]['name']);
33$people->person[0]['name'] = $people->person[0]['name'] . 'Foo';
34var_dump($people->person[0]['name']);
35$people->person[0]['name'] .= 'Bar';
36var_dump($people->person[0]['name']);
37
38echo "---ArrayOverloading---\n";
39
40$people = new Peoples;
41
42var_dump($people[0]);
43var_dump($people[0]['name']);
44var_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;
48var_dump($people[0]);
49$people[0]['name'] = 'JoeFoo';
50var_dump($people[0]['name']);
51$people[0]['name'] = 'JoeFooBar';
52var_dump($people[0]['name']);
53
54?>
55===DONE===
56--EXPECTF--
57string(3) "Joe"
58string(6) "JoeFoo"
59string(9) "JoeFooBar"
60---ArrayOverloading---
61array(1) {
62  ["name"]=>
63  string(3) "Joe"
64}
65string(3) "Joe"
66string(6) "JoeFoo"
67array(1) {
68  ["name"]=>
69  string(6) "JoeFoo"
70}
71
72Notice: Indirect modification of overloaded element of Peoples has no effect in %sarray_access_005.php on line 46
73string(6) "JoeFoo"
74
75Notice: Indirect modification of overloaded element of Peoples has no effect in %sarray_access_005.php on line 48
76string(6) "JoeFoo"
77===DONE===
78