[$offset]; }
public function offsetExists($offset) { return isset($this->data[$offset]); }
public function offsetUnset($offset) { unset($this->data); }
// isset and unset work too
//var_dump(isset($a[0][2][4][5])); // equivalent to $a[0][2][4]->offsetExists(5)
//unset($a[0][2][4][5]); // equivalent to $a[0][2][4]->offsetUnset(5);
// if __clone wasn't implemented then cloning would produce a shallow copy, and $b = clone $a; $b[0][2][4][5] = "xyzzy"; // would affect $a's data too
//echo $a[0][2][4][5]; // still "baz"
?>
max at flashdroid dot com (06-Apr-2010 09:49)
Objects implementing ArrayAccess may return objects by references in PHP 5.3.0.
You can implement your ArrayAccess object like this:
class Reflectable implements ArrayAccess {
public function set($name, $value) {
$this->{$name} = $value;
}
public function &get($name) {
return $this->{$name};
}
public function offsetGet($offset) {
return $this->get($offset);
}
public function offsetSet($offset, $value) {
$this->set($offset, $value);
}
...
}
This base class allows you to get / set your object properties using the [] operator just like in Javascript: