3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A implements ArrayAccess { function offsetGet($a){ return new A; } function offsetExists($a){ echo "exists"; if($a === 10){ return true; }else{ return false; } } function offsetSet($a, $b){} function offsetUnset($a){} } $x = new A; var_dump($x[10][20] ?? 20);
Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
Deprecated: Return type of A::offsetExists($a) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/fU7LA on line 9 Deprecated: Return type of A::offsetGet($a) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/fU7LA on line 5 Deprecated: Return type of A::offsetSet($a, $b) 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/fU7LA on line 18 Deprecated: Return type of A::offsetUnset($a) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/fU7LA on line 19 existsexistsint(20)
Output for 7.0.6 - 7.0.20, 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
existsexistsint(20)
Output for 7.0.0 - 7.0.5
object(A)#3 (0) { }
Output for 5.5.0 - 5.5.35, 5.6.0 - 5.6.28
Parse error: syntax error, unexpected '?' in /in/fU7LA on line 25
Process exited with code 255.

preferences:
69.08 ms | 411 KiB | 5 Q