I'm experimenting with the new arrow functions in PHP 7.4 and i'm trying to create a recursive arrow function one liner. Does anybody know if this is possible?
Here's my code:
$factorial = fn($x) => $x === 1 ? 1 : $x * $factorial($x - 1);
I am getting an undefined variable here. I'm assuming the inner $factorial
variable does not exist yet?
Error message Notice: Undefined variable: factorial in test.php on line 10