Closure::getCurrent() To Reach The Closure

By Tim MacDonald

<?php

    $fibonnacci = function (int $n, $previous2 = 0, $previous1 = 1) {
    if ($n <= 1) {
        return $previous2 + $previous1;
    }

    $closure = Closure::getCurrent();
    return $closure($n - 1, $previous1, $previous1 + $previous2);
};
print $fibonnacci(4);

I was happy to see PHP add Closure::getCurrent().

Now I’m using it, I can’t help but think we should add a Closure::callCurrent(/* ... */).

I don’t want to assign a variable, I don’t need the thing. Invoking the return of a function inline also feels needlessly clunky.

See Also

PHP Features

Last updated: 15 July 2026