3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait X{ function test(A $a){} function tryA(A $a){ $this->test($a); } } trait Y{ function test(B $b){} function tryB(B $b){ $this->test($b); } } class Test{ use X, Y{ X::test insteadof Y; } } class A{} class B{} $x = new Test; $x->tryA(new A); $x->tryB(new B);
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught TypeError: Test::test(): Argument #1 ($a) must be of type A, B given, called in /in/R8ZKl on line 15 and defined in /in/R8ZKl:4 Stack trace: #0 /in/R8ZKl(15): Test->test(Object(B)) #1 /in/R8ZKl(30): Test->tryB(Object(B)) #2 {main} thrown in /in/R8ZKl on line 4
Process exited with code 255.
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Test has a deprecated constructor in /in/R8ZKl on line 20 Fatal error: Uncaught ArgumentCountError: Too few arguments to function Test::test(), 0 passed in /in/R8ZKl on line 28 and exactly 1 expected in /in/R8ZKl:4 Stack trace: #0 /in/R8ZKl(28): Test->test() #1 {main} thrown in /in/R8ZKl on line 4
Process exited with code 255.
Output for 7.3.32 - 7.3.33
Fatal error: Uncaught ArgumentCountError: Too few arguments to function Test::test(), 0 passed in /in/R8ZKl on line 28 and exactly 1 expected in /in/R8ZKl:4 Stack trace: #0 /in/R8ZKl(28): Test->test() #1 {main} thrown in /in/R8ZKl on line 4
Process exited with code 255.
Output for 7.0.0 - 7.0.33
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Test has a deprecated constructor in /in/R8ZKl on line 20 Fatal error: Uncaught TypeError: Argument 1 passed to Test::test() must be an instance of A, none given, called in /in/R8ZKl on line 28 and defined in /in/R8ZKl:4 Stack trace: #0 /in/R8ZKl(28): Test->test() #1 {main} thrown in /in/R8ZKl on line 4
Process exited with code 255.
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
Catchable fatal error: Argument 1 passed to Test::test() must be an instance of A, none given, called in /in/R8ZKl on line 28 and defined in /in/R8ZKl on line 4
Process exited with code 255.

preferences:
246.99 ms | 402 KiB | 376 Q