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 LOL{ use X, Y{ X::test insteadof Y; } } class A{} class B{} $x = new LOL; $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: LOL::test(): Argument #1 ($a) must be of type A, B given, called in /in/GhNmN on line 15 and defined in /in/GhNmN:4 Stack trace: #0 /in/GhNmN(15): LOL->test(Object(B)) #1 /in/GhNmN(30): LOL->tryB(Object(B)) #2 {main} thrown in /in/GhNmN on line 4
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Fatal error: Uncaught TypeError: Argument 1 passed to LOL::test() must be an instance of A, instance of B given, called in /in/GhNmN on line 15 and defined in /in/GhNmN:4 Stack trace: #0 /in/GhNmN(15): LOL->test(Object(B)) #1 /in/GhNmN(30): LOL->tryB(Object(B)) #2 {main} thrown in /in/GhNmN on line 4
Process exited with code 255.
Output for 5.4.2 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28
Catchable fatal error: Argument 1 passed to LOL::test() must be an instance of A, instance of B given, called in /in/GhNmN on line 15 and defined in /in/GhNmN on line 4
Process exited with code 255.

preferences:
200.47 ms | 402 KiB | 272 Q