3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class A0 { public function __toString() { return 'a0'; } }; class A1 extends A0 { public function __toString() { return 'a1'; } }; $a = function ($a) : A0 {return $a;}; echo '' . $a((new A0())), '' . $a((new A1())), '' . $a(null);;
based on HrSmh
Output for 7.0.0 - 7.2.0
a0a1 Fatal error: Uncaught TypeError: Return value of {closure}() must be an instance of A0, null returned in /in/V1tdo:5 Stack trace: #0 /in/V1tdo(7): {closure}(NULL) #1 {main} thrown in /in/V1tdo on line 5
Process exited with code 255.
Output for 5.3.22 - 5.6.21
Parse error: syntax error, unexpected ':', expecting '{' in /in/V1tdo on line 5
Process exited with code 255.