summaryrefslogtreecommitdiff
path: root/tests/classes/array_access_010.phpt
blob: 175ac3abde958d9127745ba8c96f2a6a0c03d08d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
--TEST--
ZE2 ArrayAccess and ArrayReferenceProxy with references
--FILE--
<?php 

// NOTE: This will become part of SPL

class ArrayReferenceProxy implements ArrayAccess
{
	private $object;
	private $element;
	
	function __construct(ArrayAccess $object, array &$element)
	{
		echo __METHOD__ . "($element)\n";
		$this->object = $object;
		$this->element = &$element;
	}

	function offsetExists($index) {
		echo __METHOD__ . "($this->element, $index)\n";
		return array_key_exists($index, $this->element);
	}

	function offsetGet($index) {
		echo __METHOD__ . "($this->element, $index)\n";
		return isset($this->element[$index]) ? $this->element[$index] : NULL;
	}

	function offsetSet($index, $value) {
		echo __METHOD__ . "($this->element, $index, $value)\n";
		$this->element[$index] = $value;
	}

	function offsetUnset($index) {
		echo __METHOD__ . "($this->element, $index)\n";
		unset($this->element[$index]);
	}
}

class Peoples implements ArrayAccess
{
	public $person;
	
	function __construct()
	{
		$this->person = array(array('name'=>'Foo'));
	}

	function offsetExists($index)
	{
		return array_key_exists($index, $this->person);
	}

	function offsetGet($index)
	{
		return new ArrayReferenceProxy($this, $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'] . 'Bar';
var_dump($people->person[0]['name']);
$people->person[0]['name'] .= 'Baz';
var_dump($people->person[0]['name']);

echo "===ArrayOverloading===\n";

$people = new Peoples;

var_dump($people[0]);
var_dump($people[0]['name']);
$people[0]['name'] = 'FooBar';
var_dump($people[0]['name']);
$people[0]['name'] = $people->person[0]['name'] . 'Bar';
var_dump($people[0]['name']);
$people[0]['name'] .= 'Baz';
var_dump($people[0]['name']);
unset($people[0]['name']);
var_dump($people[0]);
var_dump($people[0]['name']);
$people[0]['name'] = 'BlaBla';
var_dump($people[0]['name']);

?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
unicode(3) "Foo"
unicode(6) "FooBar"
unicode(9) "FooBarBaz"
===ArrayOverloading===

Notice: Array to string conversion in %s on line %d
ArrayReferenceProxy::__construct(Array)
object(ArrayReferenceProxy)#%d (2) {
  [u"object":u"ArrayReferenceProxy":private]=>
  object(Peoples)#%d (1) {
    [u"person"]=>
    array(1) {
      [0]=>
      &array(1) {
        [u"name"]=>
        unicode(3) "Foo"
      }
    }
  }
  [u"element":u"ArrayReferenceProxy":private]=>
  &array(1) {
    [u"name"]=>
    unicode(3) "Foo"
  }
}

Notice: Array to string conversion in %s on line %d
ArrayReferenceProxy::__construct(Array)

Notice: Array to string conversion in %s on line %d
ArrayReferenceProxy::offsetGet(Array, name)
unicode(3) "Foo"

Notice: Array to string conversion in %s on line %d
ArrayReferenceProxy::__construct(Array)

Notice: Array to string conversion in %s on line %d
ArrayReferenceProxy::offsetSet(Array, name, FooBar)

Notice: Array to string conversion in %s on line %d
ArrayReferenceProxy::__construct(Array)

Notice: Array to string conversion in %s on line %d
ArrayReferenceProxy::offsetGet(Array, name)
unicode(6) "FooBar"

Notice: Array to string conversion in %s on line %d
ArrayReferenceProxy::__construct(Array)

Notice: Array to string conversion in %s on line %d
ArrayReferenceProxy::offsetSet(Array, name, FooBarBar)

Notice: Array to string conversion in %s on line %d
ArrayReferenceProxy::__construct(Array)

Notice: Array to string conversion in %s on line %d
ArrayReferenceProxy::offsetGet(Array, name)
unicode(9) "FooBarBar"

Notice: Array to string conversion in %s on line %d
ArrayReferenceProxy::__construct(Array)

Notice: Array to string conversion in %s on line %d
ArrayReferenceProxy::offsetGet(Array, name)

Notice: Array to string conversion in %s on line %d
ArrayReferenceProxy::offsetSet(Array, name, FooBarBarBaz)

Notice: Array to string conversion in %s on line %d
ArrayReferenceProxy::__construct(Array)

Notice: Array to string conversion in %s on line %d
ArrayReferenceProxy::offsetGet(Array, name)
unicode(12) "FooBarBarBaz"

Notice: Array to string conversion in %s on line %d
ArrayReferenceProxy::__construct(Array)

Notice: Array to string conversion in %s on line %d
ArrayReferenceProxy::offsetUnset(Array, name)

Notice: Array to string conversion in %s on line %d
ArrayReferenceProxy::__construct(Array)
object(ArrayReferenceProxy)#%d (2) {
  [u"object":u"ArrayReferenceProxy":private]=>
  object(Peoples)#%d (1) {
    [u"person"]=>
    array(1) {
      [0]=>
      &array(0) {
      }
    }
  }
  [u"element":u"ArrayReferenceProxy":private]=>
  &array(0) {
  }
}

Notice: Array to string conversion in %s on line %d
ArrayReferenceProxy::__construct(Array)

Notice: Array to string conversion in %s on line %d
ArrayReferenceProxy::offsetGet(Array, name)
NULL

Notice: Array to string conversion in %s on line %d
ArrayReferenceProxy::__construct(Array)

Notice: Array to string conversion in %s on line %d
ArrayReferenceProxy::offsetSet(Array, name, BlaBla)

Notice: Array to string conversion in %s on line %d
ArrayReferenceProxy::__construct(Array)

Notice: Array to string conversion in %s on line %d
ArrayReferenceProxy::offsetGet(Array, name)
unicode(6) "BlaBla"
===DONE===