3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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 7.1.0 - 7.3.0alpha1
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 hhvm-3.22.0
Fatal error: Uncaught Error: Parameter $messages is variadic and has a type constraint (Message); variadic params with type constraints are not supported in non-Hack files in /in/3UdED:-1 Stack trace: #0 {main}
Process exited with code 255.
Output for hhvm-3.18.5 - 3.21.3
Fatal error: Uncaught Error: Parameter $messages is variadic and has a type constraint (Message); variadic params with type constraints are not supported in non-Hack files in /in/3UdED:7 Stack trace: #0 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.30
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.