PHP 8.5 added Closure::getCurrent(), which returns the closure currently executing so it can recurse without capturing itself. It fails in the REPL:
phunkie > $f = function () { return Closure::getCurrent() instanceof Closure; }
$f: Callable = <function>
phunkie > $f()
Error: Evaluation error: Function call failed: Closure evaluation failed: Static call failed: Current function is not a closure
The same code works under php -r.
The cause is structural rather than a missing branch: the REPL interprets closure bodies itself (evaluateClosure / evaluateArrowFunction walk the AST) instead of compiling a real PHP closure, so at the point Closure::getCurrent() runs there is no enclosing PHP closure on the stack for it to return.
Filed for visibility rather than as an easy fix - honouring it means either compiling user closures into real closures, or special-casing Closure::getCurrent() to return the interpreted closure the evaluator is currently inside. The second is narrower and probably the right first step.
Lower priority than the other gaps, since getCurrent() is a niche convenience, but it is the one PHP 8.5 feature that the REPL's interpretation strategy actively prevents rather than merely not having got to yet.
PHP 8.5 added
Closure::getCurrent(), which returns the closure currently executing so it can recurse without capturing itself. It fails in the REPL:The same code works under
php -r.The cause is structural rather than a missing branch: the REPL interprets closure bodies itself (
evaluateClosure/evaluateArrowFunctionwalk the AST) instead of compiling a real PHP closure, so at the pointClosure::getCurrent()runs there is no enclosing PHP closure on the stack for it to return.Filed for visibility rather than as an easy fix - honouring it means either compiling user closures into real closures, or special-casing
Closure::getCurrent()to return the interpreted closure the evaluator is currently inside. The second is narrower and probably the right first step.Lower priority than the other gaps, since
getCurrent()is a niche convenience, but it is the one PHP 8.5 feature that the REPL's interpretation strategy actively prevents rather than merely not having got to yet.