Skip to content

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

Open
@tobia

Description

@tobia

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions