3v4l.org

run code in 300+ PHP versions simultaneously
<?php function is_even(int $n): bool { if ($n < 0) { $n = abs($n); } var_dump($n); if ($n === 0) { return true; } if ($n === 1) { return false; } return is_even($n - 1); } var_dump(is_even(-4)); die(); for($i = -5; $i <= 12; $i++) { printf('is %d even? %s.%s', $i, is_even($i) ? 'yes': 'no', "\n"); }
based on RHKTm
Output for 7.2.0 - 7.2.32, 7.3.0 - 7.3.20, 7.4.0 - 7.4.8, 8.0.0alpha1 - alpha3
int(4) int(3) int(2) int(1) bool(false)