3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(E_ALL); class MyArray implements ArrayAccess { public $value; public function __construct($value = null) { $this->value = $value; } public function &offsetGet($offset) { var_dump(__METHOD__); if (!isset($this->value[$offset])) { throw new Exception('Undefined index: ' . $offset); } return $this->value[$offset]; } public function offsetExists($offset) { var_dump(__METHOD__); return isset($this->value[$offset]); } public function offsetSet($offset, $value) { var_dump(__METHOD__); $this->value[$offset] = $value; } public function offsetUnset($offset) { var_dump(__METHOD__); $this->value[$offset] = null; } } $record = new MyArray([ 'foo' => [ 'bar' => 'baz' ] ]); var_dump(isset($record['foo']['bar'])); var_dump(isset($record['hello']['world']));
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Deprecated: Return type of MyArray::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/7C2Fs on line 25 Deprecated: Return type of & MyArray::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/7C2Fs on line 14 Deprecated: Return type of MyArray::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/7C2Fs on line 32 Deprecated: Return type of MyArray::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/7C2Fs on line 39 string(21) "MyArray::offsetExists" string(18) "MyArray::offsetGet" bool(true) string(21) "MyArray::offsetExists" bool(false)
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Deprecated: Return type of MyArray::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/7C2Fs on line 25 Deprecated: Return type of & MyArray::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/7C2Fs on line 14 Deprecated: Return type of MyArray::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/7C2Fs on line 32 Deprecated: Return type of MyArray::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/7C2Fs on line 39 string(21) "MyArray::offsetExists" string(18) "MyArray::offsetGet" bool(true) string(21) "MyArray::offsetExists" bool(false)
Output for 7.0.6 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
string(21) "MyArray::offsetExists" string(18) "MyArray::offsetGet" bool(true) string(21) "MyArray::offsetExists" bool(false)
Output for 7.0.0 - 7.0.5
string(18) "MyArray::offsetGet" bool(true) string(18) "MyArray::offsetGet" Fatal error: Uncaught Exception: Undefined index: hello in /in/7C2Fs:19 Stack trace: #0 /in/7C2Fs(54): MyArray->offsetGet('hello') #1 {main} thrown in /in/7C2Fs on line 19
Process exited with code 255.
Output for 5.6.0 - 5.6.40
string(18) "MyArray::offsetGet" bool(true) string(18) "MyArray::offsetGet" Fatal error: Uncaught exception 'Exception' with message 'Undefined index: hello' in /in/7C2Fs:19 Stack trace: #0 /in/7C2Fs(54): MyArray->offsetGet('hello') #1 {main} thrown in /in/7C2Fs on line 19
Process exited with code 255.

preferences:
239.93 ms | 401 KiB | 300 Q