3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class Collection extends ArrayObject { private $data; function __construct() { $this->data = array(); parent::__construct($this->data); } function offsetGet($index) { echo __METHOD__ . "($index)\n"; return parent::offsetGet($index); } function offsetSet($index, $value) { echo __METHOD__ . "(" . (is_null($index) ? "NULL" : $index) . ",$value)\n"; parent::offsetSet($index, $value); } } echo "\n\nInitiate Obj\n"; $arrayObj = new Collection(); echo "Assign values\n"; $arrayObj[] = "foo"; var_dump($arrayObj[0]); $arrayObj[] = "bar"; var_dump($arrayObj[0]); var_dump($arrayObj[1]); $arrayObj["foo"] = "baz"; var_dump($arrayObj["foo"]); print_r($arrayObj); var_dump(count($arrayObj));
based on JHpm0
Output for 5.3.0 - 7.1.0
Initiate Obj Assign values Collection::offsetSet(NULL,foo) Collection::offsetGet(0) string(3) "foo" Collection::offsetSet(NULL,bar) Collection::offsetGet(0) string(3) "foo" Collection::offsetGet(1) string(3) "bar" Collection::offsetSet(foo,baz) Collection::offsetGet(foo) string(3) "baz" Collection Object ( [data:Collection:private] => Array ( ) [storage:ArrayObject:private] => Array ( [0] => foo [1] => bar [foo] => baz ) ) int(3)
Output for 5.1.0 - 5.2.17
Initiate Obj Assign values Collection::offsetSet(NULL,foo) Collection::offsetGet(0) string(3) "foo" Collection::offsetSet(NULL,bar) Collection::offsetGet(0) string(3) "foo" Collection::offsetGet(1) string(3) "bar" Collection::offsetSet(foo,baz) Collection::offsetGet(foo) string(3) "baz" Collection Object ( [0] => foo [1] => bar [foo] => baz ) int(3)
Output for 5.0.4 - 5.0.5
Initiate Obj Assign values
Process exited with code 139.
Output for 5.0.0 - 5.0.3
Initiate Obj Assign values string(3) "foo" string(3) "foo" string(3) "bar" string(3) "baz" Collection Object ( [0] => foo [1] => bar [foo] => baz ) int(3)
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/Gi6SO on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/Gi6SO on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/Gi6SO on line 5
Process exited with code 255.