3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Message {} class WrongMessage {} function test(Message ...$messages) { var_dump($messages); } $messages = [new Message(), new Message]; $messagesWithSuprise = [new Message(), new WrongMessage()]; test(...$messages); test(new Message, new Message); test(...$messagesWithSuprise);
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
array(2) { [0]=> object(Message)#1 (0) { } [1]=> object(Message)#2 (0) { } } array(2) { [0]=> object(Message)#5 (0) { } [1]=> object(Message)#6 (0) { } } Fatal error: Uncaught TypeError: test(): Argument #2 must be of type Message, WrongMessage given, called in /in/3UdED on line 17 and defined in /in/3UdED:7 Stack trace: #0 /in/3UdED(17): test(Object(Message), Object(WrongMessage)) #1 {main} thrown in /in/3UdED on line 7
Process exited with code 255.
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 array(2) { [0]=> object(Message)#1 (0) { } [1]=> object(Message)#2 (0) { } } array(2) { [0]=> object(Message)#5 (0) { } [1]=> object(Message)#6 (0) { } } Fatal error: Uncaught TypeError: test(): Argument #2 must be of type Message, WrongMessage given, called in /in/3UdED on line 17 and defined in /in/3UdED:7 Stack trace: #0 /in/3UdED(17): test(Object(Message), Object(WrongMessage)) #1 {main} thrown in /in/3UdED on line 7
Process exited with code 255.
Output for 7.0.33, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
array(2) { [0]=> object(Message)#1 (0) { } [1]=> object(Message)#2 (0) { } } array(2) { [0]=> object(Message)#5 (0) { } [1]=> object(Message)#6 (0) { } } Fatal error: Uncaught TypeError: Argument 2 passed to test() must be an instance of Message, instance of WrongMessage given, called in /in/3UdED on line 17 and defined in /in/3UdED:7 Stack trace: #0 /in/3UdED(17): test(Object(Message), Object(WrongMessage)) #1 {main} thrown in /in/3UdED on line 7
Process exited with code 255.
Output for 5.6.38
array(2) { [0]=> object(Message)#1 (0) { } [1]=> object(Message)#2 (0) { } } array(2) { [0]=> object(Message)#5 (0) { } [1]=> object(Message)#6 (0) { } } Catchable fatal error: Argument 2 passed to test() must be an instance of Message, instance of WrongMessage given, called in /in/3UdED on line 17 and defined in /in/3UdED on line 7
Process exited with code 255.

preferences:
178.68 ms | 402 KiB | 180 Q