3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php error_reporting(-1); class obj implements ArrayAccess { private $container = array(); public function __construct() { $this->container = array( "one" => 1, "two" => 2, "three" => 3, ); } public function offsetSet($offset, $value) { if (is_null($offset)) { $this->container[] = $value; } else { $this->container[$offset] = $value; } } public function offsetExists($offset) { return isset($this->container[$offset]); } public function offsetUnset($offset) { unset($this->container[$offset]); } public function offsetGet($offset) { return isset($this->container[$offset]) ? $this->container[$offset] : null; } } $obj = new obj; var_dump(isset($obj["two"])); var_dump($obj["two"]); unset($obj["two"]); var_dump(isset($obj["two"])); $obj["two"] = "A value"; var_dump($obj["two"]); $obj[] = 'Append 1'; $obj[] = 'Append 2'; $obj[] = 'Append 3'; $obj[][0] = 'Append 4';
based on qTpug
Output for 5.5.0 - 5.6.28, 7.0.6 - 7.2.0
bool(true) int(2) bool(false) string(7) "A value" Notice: Indirect modification of overloaded element of obj has no effect in /in/uMrcs on line 47
Output for 7.0.0 - 7.0.5
bool(true) int(2) bool(false) string(7) "A value" Notice: Undefined variable: offset in /in/uMrcs on line 32 Notice: Indirect modification of overloaded element of obj has no effect in /in/uMrcs on line 47