3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ArrayAccessImplementer implements ArrayAccess { private $array; public function __construct(array $array) { $this->array = $array; } public function offsetExists($offset) { return array_key_exists($this->array, $offset); } public function offsetSet($offset, $value) { $this->array[$offset] = $value; } public function offsetGet($offset) { return $this->array[$offset]; } public function offsetUnset($offset) { unset($this->array[$offset]); } } class ArrayObjectSubClass extends ArrayObject { } class SimpleObject { private $test; public function __construct(array $array) { $this->test = $array['test']; } } $inputArray = array('test' => 'value1'); $stdClassObject = (object)$inputArray; $simpleObject = new SimpleObject($inputArray); $arrayObject = new ArrayObject($inputArray); $arrayObjectSubclass = new ArrayObjectSubClass($inputArray); $arrayAccess = new ArrayAccessImplementer($inputArray); echo 'stdClass: '; var_export((array)$stdClassObject); echo PHP_EOL, 'SimpleObject: '; var_export((array)$simpleObject); echo PHP_EOL, 'ArrayObject: '; var_export((array)$arrayObject); echo PHP_EOL, 'ArrayObjectSubclass: '; var_export((array)$arrayObjectSubclass); echo PHP_EOL, 'ArrayAccess: '; var_export((array)$arrayAccess);
based on a9MIr
Output for 5.2.6 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.30, 7.0.0 - 7.0.20, 7.1.0 - 7.1.7, 7.2.29 - 7.2.33, 7.3.16 - 7.3.24, 7.4.2 - 7.4.13, 8.0.0
stdClass: array ( 'test' => 'value1', ) SimpleObject: array ( '' . "\0" . 'SimpleObject' . "\0" . 'test' => 'value1', ) ArrayObject: array ( 'test' => 'value1', ) ArrayObjectSubclass: array ( 'test' => 'value1', ) ArrayAccess: array ( '' . "\0" . 'ArrayAccessImplementer' . "\0" . 'array' => array ( 'test' => 'value1', ), )
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.5
stdClass: array ( 'test' => 'value1', ) SimpleObject: array ( 'SimpleObjecttest' => 'value1', ) ArrayObject: array ( 'test' => 'value1', ) ArrayObjectSubclass: array ( 'test' => 'value1', ) ArrayAccess: array ( 'ArrayAccessImplementerarray' => array ( 'test' => 'value1', ), )
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in /in/ti4aY on line 7
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting '{' in /in/ti4aY on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting '{' in /in/ti4aY on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'{'' in /in/ti4aY on line 3
Process exited with code 255.