- var_dump: documentation ( source)
- array_key_exists: documentation ( source)
<?php
class ProfsimmException extends Exception { }
class Foo implements ArrayAccess {
public function offsetExists ( $offset ) {
return array_key_exists($this->foo[$offset]);
}
public function offsetGet ( $offset ) {
return $this->foo[$offset];
}
public function offsetSet ( $offset, $value ) {
$this->foo[$offset] = $value;
}
public function offsetUnset ( $offset ) {
unset($this->foo[$offset]);
}
}
class Bar {
private $foo;
public function __construct() {
$this->foo = new Foo();
}
public function __set($prop, $value) {
$this->$prop = $value;
}
public function __get($prop) {
if ($this->$prop instanceof \ArrayAccess) {
throw new ProfsimmException("Nope.");
}
}
}
$bar = new Bar();
$bar->foo['abc'] = 'def';
var_dump($bar);
$foo = $bar->foo;