plugin-php
plugin-php copied to clipboard
Parentheses incorrectly removed from functions defined and called on the same line
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.
Possibly related to #2333