3v4l.org

run code in 300+ PHP versions simultaneously
<?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());
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.10, 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.5.24 - 5.5.35, 5.6.8 - 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.

preferences:
65.03 ms | 402 KiB | 46 Q