3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * @param int $num1 * @param ?int $num2 If null or omitted, it will get the value 1 * * @return int */ function add($num1, $num2 = null) { // If the default value is null, set it to the default $num2 = $num2 ?? 1; print_r($num1, $num2); return $num1 + $num2; } $bool = true; echo add(5, $bool ? 5 : null) . PHP_EOL; $bool = false; echo add(5, $bool ? 5 : null) . PHP_EOL;
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
10 6

preferences:
81.02 ms | 406 KiB | 5 Q