3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types = 1); trait Foo{ public function bar(int $int){ echo $int * 2; } public function callBar(){ $this->bar(123); } } class A{ use Foo; public function bar(string $string){ // incompatible signature! // prevents callBar from working correctly } } $a = new A; $a->bar("123"); $a->callBar();
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
Fatal error: Uncaught TypeError: A::bar(): Argument #1 ($string) must be of type string, int given, called in /in/Ca8CP on line 11 and defined in /in/Ca8CP:18 Stack trace: #0 /in/Ca8CP(11): A->bar(123) #1 /in/Ca8CP(27): A->callBar() #2 {main} thrown in /in/Ca8CP on line 18
Process exited with code 255.
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Fatal error: Uncaught TypeError: Argument 1 passed to A::bar() must be of the type string, int given, called in /in/Ca8CP on line 11 and defined in /in/Ca8CP:18 Stack trace: #0 /in/Ca8CP(11): A->bar(123) #1 /in/Ca8CP(27): A->callBar() #2 {main} thrown in /in/Ca8CP on line 18
Process exited with code 255.
Output for 7.1.25 - 7.1.33, 7.2.0 - 7.2.33
Fatal error: Uncaught TypeError: Argument 1 passed to A::bar() must be of the type string, integer given, called in /in/Ca8CP on line 11 and defined in /in/Ca8CP:18 Stack trace: #0 /in/Ca8CP(11): A->bar(123) #1 /in/Ca8CP(27): A->callBar() #2 {main} thrown in /in/Ca8CP on line 18
Process exited with code 255.

preferences:
117.02 ms | 409 KiB | 5 Q