3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Foo { protected $label; public function __construct($label) { $this->label = $label; } } class Baz{} class Bar { public function test(Foo $foo = null) { if( is_null($foo) ) { $foo = new Foo('I am not magic.'); } var_dump($foo); } } $baz = new Bar(); $baz->test(new Foo('burp')); $baz->test(); $baz->test(new Baz());
Output for 7.1.0 - 7.2.4
object(Foo)#2 (1) { ["label":protected]=> string(4) "burp" } object(Foo)#2 (1) { ["label":protected]=> string(15) "I am not magic." } Fatal error: Uncaught TypeError: Argument 1 passed to Bar::test() must be an instance of Foo or null, instance of Baz given, called in /in/rc2qH on line 25 and defined in /in/rc2qH:14 Stack trace: #0 /in/rc2qH(25): Bar->test(Object(Baz)) #1 {main} thrown in /in/rc2qH on line 14
Process exited with code 255.
Output for hhvm-3.22.0
object(Foo)#2 (1) { ["label":protected]=> string(4) "burp" } object(Foo)#2 (1) { ["label":protected]=> string(15) "I am not magic." } Fatal error: Uncaught TypeError: Argument 1 passed to Bar::test() must be an instance of Foo, Baz given in /in/rc2qH:-1 Stack trace: #0 /in/rc2qH(-1): Bar->test() #1 {main}
Process exited with code 255.
Output for hhvm-3.18.5 - 3.21.3
object(Foo)#2 (1) { ["label":protected]=> string(4) "burp" } object(Foo)#2 (1) { ["label":protected]=> string(15) "I am not magic." } Fatal error: Uncaught TypeError: Argument 1 passed to Bar::test() must be an instance of Foo, Baz given in /in/rc2qH:19 Stack trace: #0 /in/rc2qH(25): Bar->test() #1 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.30
object(Foo)#2 (1) { ["label":protected]=> string(4) "burp" } object(Foo)#2 (1) { ["label":protected]=> string(15) "I am not magic." } Catchable fatal error: Argument 1 passed to Bar::test() must be an instance of Foo, instance of Baz given, called in /in/rc2qH on line 25 and defined in /in/rc2qH on line 14
Process exited with code 255.