3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types = 1); class Foo { /** * @param int $i * @return void */ public function bar($i) {} public function baz(int $i): void {} } /** * @method string bar(bool $b, object $o) * @method string baz(bool $b, object $o) */ class Woo extends Foo {} $w = new Woo(); $r1 = $w->bar(true, new \stdClass); $r2 = $w->baz(true, new \stdClass); //$r3 = $w->bar(123); //$r4 = $w->baz(123); function test(float $f) {}; test($r1); test($r2); //test($r3); //test($r4);
Output for 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
Fatal error: Uncaught TypeError: Foo::baz(): Argument #1 ($i) must be of type int, true given, called in /in/a45q7 on line 20 and defined in /in/a45q7:9 Stack trace: #0 /in/a45q7(20): Foo->baz(true, Object(stdClass)) #1 {main} thrown in /in/a45q7 on line 9
Process exited with code 255.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29
Fatal error: Uncaught TypeError: Foo::baz(): Argument #1 ($i) must be of type int, bool given, called in /in/a45q7 on line 20 and defined in /in/a45q7:9 Stack trace: #0 /in/a45q7(20): Foo->baz(true, Object(stdClass)) #1 {main} thrown in /in/a45q7 on line 9
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 Foo::baz() must be of the type int, bool given, called in /in/a45q7 on line 20 and defined in /in/a45q7:9 Stack trace: #0 /in/a45q7(20): Foo->baz(true, Object(stdClass)) #1 {main} thrown in /in/a45q7 on line 9
Process exited with code 255.
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33
Fatal error: Uncaught TypeError: Argument 1 passed to Foo::baz() must be of the type integer, boolean given, called in /in/a45q7 on line 20 and defined in /in/a45q7:9 Stack trace: #0 /in/a45q7(20): Foo->baz(true, Object(stdClass)) #1 {main} thrown in /in/a45q7 on line 9
Process exited with code 255.
Output for 5.6.0 - 5.6.40
Warning: Unsupported declare 'strict_types' in /in/a45q7 on line 1 Parse error: syntax error, unexpected ':', expecting ';' or '{' in /in/a45q7 on line 9
Process exited with code 255.

preferences:
162.56 ms | 412 KiB | 5 Q