3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface I { public function a(int $a): string; } Class C implements I { public function a(int|string $a): string { return "foo"; } } class D implements I { public function a(int $a): string { return "foo"; } } function test(I $subject) { print $subject->a('beep'); } test(new C()); test(new D());
Output for 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
foo Fatal error: Uncaught TypeError: D::a(): Argument #1 ($a) must be of type int, string given, called in /in/WUTv4 on line 21 and defined in /in/WUTv4:15 Stack trace: #0 /in/WUTv4(21): D->a('beep') #1 /in/WUTv4(25): test(Object(D)) #2 {main} thrown in /in/WUTv4 on line 15
Process exited with code 255.

preferences:
50.39 ms | 406 KiB | 5 Q