3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class ObjectToArrayConverter { /** * @param mixed $value * * @raturn array */ public static function toArray($value) { if (! (is_object($value) || is_array($value))) { return $value; } if (is_object($value) && method_exists($value, '__toArray')) { return $value->__toArray(); } return array_map(__METHOD__, (array) $value); } } clas Baz { public function __toArray() { return ['I R ARRAY']; } } $obj1 = new stdClass(); $obj2 = new stdClass(); $obj1->foo = 'foo'; $obj1->someArr = []; $obj1->obj2 = $obj2; $obj2->bar = 'bar'; $obj2->baz = new Baz(); var_dump(ObjectToArrayConverter::toArray($obj1));
Output for 5.4.0 - 5.6.1
Parse error: syntax error, unexpected 'Baz' (T_STRING) in /in/QDv0V on line 24
Process exited with code 255.
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected T_STRING in /in/QDv0V on line 24
Process exited with code 255.