3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php declare(strict_types=1); trait T { abstract function foo(): string; function bar(): string { return $this->foo(); } } abstract class A { use T; } /* class B extends A { // This fatals as expected function foo() { return 'some string'; } } */ class C { use T; // This does not function foo() { return 'some string'; } } class D { use T; // This ALSO does not function foo(): int { return 3; } } abstract class E { use T; // Nor this function foo() { return 'some thing'; } } (new D())->bar();
based on OlOJg
Output for 7.1.0 - 7.2.8
Fatal error: Uncaught TypeError: Return value of D::bar() must be of the type string, integer returned in /in/02d4a:7 Stack trace: #0 /in/02d4a(51): D->bar() #1 {main} thrown in /in/02d4a on line 7
Process exited with code 255.
Output for hhvm-3.22.0
Fatal error: Uncaught TypeError: Value returned from method D::bar() must be of type string, int given in /in/02d4a:-1 Stack trace: #0 /in/02d4a(-1): D->bar() #1 {main}
Process exited with code 255.
Output for hhvm-3.18.5 - 3.21.3
Fatal error: Uncaught TypeError: Value returned from method D::bar() must be of type string, int given in /in/02d4a:7 Stack trace: #0 /in/02d4a(51): D->bar() #1 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.30
Warning: Unsupported declare 'strict_types' in /in/02d4a on line 1 Parse error: syntax error, unexpected ':', expecting ';' or '{' in /in/02d4a on line 4
Process exited with code 255.