3v4l.org

run code in 300+ PHP versions simultaneously
<?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 git.master, git.master_jit, rfc.property-hooks
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: Bar::test(): Argument #1 ($foo) must be of type ?Foo, 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.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
51.91 ms | 401 KiB | 8 Q