3v4l.org

run code in 300+ PHP versions simultaneously
<?php class obj { function __tostring() { $GLOBALS['a'] = 'hi'; } } $a = [0, new obj, 2]; $b = ["Nula", "Jedna", "Dva"]; var_dump($a); str_replace($a, $b, "1"); var_dump($a);
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
array(3) { [0]=> int(0) [1]=> object(obj)#1 (0) { } [2]=> int(2) } Fatal error: Uncaught TypeError: obj::__tostring(): Return value must be of type string, none returned in /in/W51BS:6 Stack trace: #0 [internal function]: obj->__tostring() #1 /in/W51BS(13): str_replace(Array, Array, '1') #2 {main} thrown in /in/W51BS on line 6
Process exited with code 255.
Output for 7.4.0 - 7.4.33
array(3) { [0]=> int(0) [1]=> object(obj)#1 (0) { } [2]=> int(2) } Fatal error: Uncaught Error: Method obj::__toString() must return a string value in /in/W51BS:13 Stack trace: #0 /in/W51BS(13): str_replace(Array, Array, '1') #1 {main} thrown in /in/W51BS on line 13
Process exited with code 255.
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33
array(3) { [0]=> int(0) [1]=> object(obj)#1 (0) { } [2]=> int(2) } Recoverable fatal error: Method obj::__toString() must return a string value in /in/W51BS on line 13
Process exited with code 255.
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20
array(3) { [0]=> int(0) [1]=> object(obj)#1 (0) { } [2]=> int(2) } Catchable fatal error: Method obj::__toString() must return a string value in /in/W51BS on line 13
Process exited with code 255.

preferences:
148.52 ms | 402 KiB | 223 Q