3v4l.org

run code in 300+ PHP versions simultaneously
<?php class foo { function __toString() { return "x"; } } $foo = new foo; var_dump(strpos($foo, "x")); var_dump(strpos("x", $foo)); $array = array("x" => "y"); var_dump($array[$foo]); var_dump($foo[0]); ?>
Output for 8.3.0 - 8.3.6
int(0) int(0) Fatal error: Uncaught TypeError: Cannot access offset of type foo on array in /in/V8dU4:11 Stack trace: #0 {main} thrown in /in/V8dU4 on line 11
Process exited with code 255.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18
int(0) int(0) Fatal error: Uncaught TypeError: Illegal offset type in /in/V8dU4:11 Stack trace: #0 {main} thrown in /in/V8dU4 on line 11
Process exited with code 255.
Output for 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
int(0) Notice: Object of class foo could not be converted to int in /in/V8dU4 on line 9 Deprecated: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in /in/V8dU4 on line 9 bool(false) Warning: Illegal offset type in /in/V8dU4 on line 11 NULL Fatal error: Uncaught Error: Cannot use object of type foo as array in /in/V8dU4:12 Stack trace: #0 {main} thrown in /in/V8dU4 on line 12
Process exited with code 255.
Output for 7.3.32 - 7.3.33
int(0) bool(false) Warning: Illegal offset type in /in/V8dU4 on line 11 NULL Fatal error: Uncaught Error: Cannot use object of type foo as array in /in/V8dU4:12 Stack trace: #0 {main} thrown in /in/V8dU4 on line 12
Process exited with code 255.
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33
int(0) Notice: Object of class foo could not be converted to int in /in/V8dU4 on line 9 bool(false) Warning: Illegal offset type in /in/V8dU4 on line 11 NULL Fatal error: Uncaught Error: Cannot use object of type foo as array in /in/V8dU4:12 Stack trace: #0 {main} thrown in /in/V8dU4 on line 12
Process exited with code 255.
Output for 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
int(0) Notice: Object of class foo could not be converted to int in /in/V8dU4 on line 9 bool(false) Warning: Illegal offset type in /in/V8dU4 on line 11 NULL Fatal error: Cannot use object of type foo as array in /in/V8dU4 on line 12
Process exited with code 255.
Output for 5.1.0 - 5.1.6
Notice: Object of class foo to string conversion in /in/V8dU4 on line 8 bool(false) Notice: Object of class foo could not be converted to int in /in/V8dU4 on line 9 bool(false) Warning: Illegal offset type in /in/V8dU4 on line 11 NULL Fatal error: Cannot use object of type foo as array in /in/V8dU4 on line 12
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Notice: Object of class foo to string conversion in /in/V8dU4 on line 8 bool(false) bool(false) Warning: Illegal offset type in /in/V8dU4 on line 11 NULL Fatal error: Cannot use object of type foo as array in /in/V8dU4 on line 12
Process exited with code 255.
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9
Notice: Object to string conversion in /in/V8dU4 on line 8 bool(false) bool(false) Warning: Illegal offset type in /in/V8dU4 on line 11 NULL NULL

preferences:
318.88 ms | 402 KiB | 459 Q