3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); function foo(int $x, int $y = 2, ?int &$z = null) { var_dump(func_num_args()); $z = $x ** 2; return $x * $y; } $a = 'a'; var_dump([foo(5, z: $a), $a]); var_dump([foo(3, -1)]);
Output for 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
Fatal error: Uncaught TypeError: foo(): Argument #3 ($z) must be of type ?int, string given, called in /in/bIDtq on line 12 and defined in /in/bIDtq:5 Stack trace: #0 /in/bIDtq(12): foo(5, 2, 'a') #1 {main} thrown in /in/bIDtq on line 5
Process exited with code 255.

preferences:
50.84 ms | 406 KiB | 5 Q