plugin-php icon indicating copy to clipboard operation
plugin-php copied to clipboard

Parentheses incorrectly removed from functions defined and called on the same line

Open tobia opened this issue 1 year ago • 1 comments

This code, which recursively computes the 10th Fibonacci number:

$result = ($fib = function($n) use (&$fib) {
    return $n <= 1 ? $n : $fib($n - 1) + $fib($n - 2);
})(10);

is incorrectly simplified to this:

$result = $fib = function ($n) use (&$fib) {
    return $n <= 1 ? $n : $fib($n - 1) + $fib($n - 2);
}(10);

removing the parentheses leads to incorrect code.

tobia avatar Nov 26 '24 20:11 tobia

Possibly related to #2333

tobia avatar Nov 26 '24 20:11 tobia