3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class MyThing implements \ArrayAccess { protected $storage = []; public function __construct($values = array()) { foreach ($values as $name => $value) { $this->offsetSet($name, $value); } } public function offsetGet($name) { if (isset($this->storage[$name])) { return $this->storage[$name]; } } public function offsetSet($name, $value) { $this->storage[$name] = $value; } public function offsetUnset($name) { unset($this->storage[$name]); } public function offsetExists($name) { return isset($this->storage[$name]); } } function printArray(array $a) { print_r($a); } $thing = new MyThing(['foo' => 'bar']); printArray($thing);
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught TypeError: Argument 1 passed to printArray() must be of the type array, object given, called in /in/B3ngF on line 37 and defined in /in/B3ngF:32 Stack trace: #0 /in/B3ngF(37): printArray(Object(MyThing)) #1 {main} thrown in /in/B3ngF on line 32
Process exited with code 255.
Output for 5.4.10 - 5.6.28
Catchable fatal error: Argument 1 passed to printArray() must be of the type array, object given, called in /in/B3ngF on line 37 and defined in /in/B3ngF on line 32
Process exited with code 255.
Output for 5.3.20 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/B3ngF on line 4
Process exited with code 255.