3v4l.org

run code in 300+ PHP versions simultaneously
<?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;

preferences:
28.68 ms | 402 KiB | 5 Q