3v4l.org

run code in 300+ PHP versions simultaneously
<?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';
Output for 8.5.0 - 8.5.2
Deprecated: Return type of obj::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/uMrcs on line 23 Deprecated: Return type of obj::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/uMrcs on line 31 Deprecated: Return type of obj::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/uMrcs on line 15 Deprecated: Return type of obj::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/uMrcs on line 27 bool(true) int(2) bool(false) string(7) "A value" Deprecated: Using null as an array offset is deprecated, use an empty string instead in /in/uMrcs on line 32 Notice: Indirect modification of overloaded element of obj has no effect in /in/uMrcs on line 47
Output for 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.14, 8.4.16 - 8.4.17
Deprecated: Return type of obj::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/uMrcs on line 23 Deprecated: Return type of obj::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/uMrcs on line 31 Deprecated: Return type of obj::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/uMrcs on line 15 Deprecated: Return type of obj::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/uMrcs on line 27 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 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.6 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
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

preferences:
205.31 ms | 414 KiB | 5 Q