3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait A { abstract function foo(); } trait B { abstract function foo(): stdclass; } class C { use A; use B; function foo(): stdClass{ // valid for both A (mixed) and B (stdClass) return new stdClass; } } $x = new C(); var_dump($x->foo());
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.27, 8.4.1 - 8.4.14
object(stdClass)#2 (0) { }
Output for 7.4.0 - 7.4.33
Fatal error: Declaration of A::foo() must be compatible with B::foo(): stdclass in /in/54BJG on line 5
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33
Fatal error: Declaration of A::foo() must be compatible with B::foo(): stdclass in /in/54BJG on line 13
Process exited with code 255.
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.25
Fatal error: Declaration of B::foo(): stdclass must be compatible with A::foo() in /in/54BJG on line 13
Process exited with code 255.
Output for 5.6.38
Parse error: syntax error, unexpected ':', expecting ';' or '{' in /in/54BJG on line 10
Process exited with code 255.

preferences:
131.64 ms | 411 KiB | 5 Q