Code: Select all
class Foo implements ArrayAccess{
private $data;
public function offsetGet($var) {
return $this->data[$var];
}
public function offsetSet($var, $value) {
$this->data[$var] = $value;
}
public function offsetExists($var) {
return isset($this->data[$var]);
}
public function offsetUnset($var) {
unset($this->data[$var]);
}
}
Code: Select all
$foo = new Foo();
$foo['stinky'] = 'weaselteats';
$ref =& $foo['stinky'];
Fatal error: Objects used as arrays in post/pre increment/decrement must return values by reference in foo.php.
Soooooooooo.... i tried changing the method definition of Foo::offsetGet() to return a reference like so...
Code: Select all
...
public function &offsetGet($var){
return $this->data[$var];
}
...
Fatal error: Declaration of Foo::offsetGet() must be compatible with that of ArrayAccess::offsetGet() in foo.php
I can get both errors to go away by not attempting to assign the reference in the implementation like so...
Code: Select all
$ref = $foo['stinky'];
// no errors - but this is not what I want