3v4l.org

run code in 300+ PHP versions simultaneously
<?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();
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.29, 8.2.0 - 8.2.20, 8.3.0 - 8.3.8
Fatal error: Declaration of C::foo() must be compatible with T::foo(): string in /in/02d4a on line 28
Process exited with code 255.
Output for 7.3.16 - 7.3.33, 7.4.0 - 7.4.33
Fatal error: Uncaught TypeError: Return value of D::bar() must be of the type string, int 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 7.1.0 - 7.1.20, 7.2.0 - 7.2.33
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.

preferences:
133.26 ms | 402 KiB | 166 Q