3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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); try { $foo = $bar->foo; } catch (\ProfsimmException $ex) { var_dump($ex); }
based on 76auA
Output for 7.0.0 - 7.3.0beta1
Fatal error: Uncaught ProfsimmException: Nope. in /in/c67S2:36 Stack trace: #0 /in/c67S2(43): Bar->__get('foo') #1 {main} thrown in /in/c67S2 on line 36
Process exited with code 255.
Output for hhvm-3.15.4
Fatal error: Uncaught exception 'ProfsimmException' with message 'Nope.' in /in/c67S2:36 Stack trace: #0 /in/c67S2(43): Bar->__get() #1 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.30
Fatal error: Uncaught exception 'ProfsimmException' with message 'Nope.' in /in/c67S2:36 Stack trace: #0 /in/c67S2(43): Bar->__get('foo') #1 {main} thrown in /in/c67S2 on line 36
Process exited with code 255.