3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php declare(strict_types = 1); phpversion() >= "7.0.0" or die(); function myErrorHandler($errno, $errstr, $errfile, $errline) { if ( E_RECOVERABLE_ERROR===$errno ) { echo "'catched' catchable fatal error\n"; return true; } return false; } set_error_handler('myErrorHandler'); class FooBar { public $prop = '123'; } class BarFoo { public $prop = '312'; } function test () : FooBar { return new FooBar; } function test1 () : BarFoo { return new FooBar; } try { var_dump(test1()); } catch (Exception $e) { var_dump($e->getMessage()); } var_dump(test());
based on vt15o
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught TypeError: Return value of test1() must be an instance of BarFoo, instance of FooBar returned in /in/5eh2H:28 Stack trace: #0 /in/5eh2H(32): test1() #1 {main} thrown in /in/5eh2H on line 28
Process exited with code 255.
Output for 5.3.20 - 5.6.28
Warning: Unsupported declare 'strict_types' in /in/5eh2H on line 2 Parse error: syntax error, unexpected ':', expecting '{' in /in/5eh2H on line 23
Process exited with code 255.