Category
language
Problem
Closure::fromCallable() and Closure::bindTo() are not available on the VM builtin Closure class. PHP 7.1+ code uses fromCallable for first-class callables; bindTo rebinding is distinct from Closure::bind() tracked in #3097.
php-src reference
Zend/zend_closures.c — zend_closure_from_callable, zend_closure_bind_to
ext/standard/basic_functions.c — userland exposure
Repro (today)
<?php
class C {
private function secret(): string { return 'ok'; }
public function get(): Closure {
return Closure::fromCallable([$this, 'secret']);
}
}
$c = new C();
echo ($c->get())();
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php repro-from-callable.php'
# LogicException / undefined method fromCallable
php repro-from-callable.php
# Zend: ok
bindTo repro
<?php
$fn = function () { return $this->x; };
class D { public int $x = 42; }
$bound = $fn->bindTo(new D(), D::class);
echo $bound();
Scope (this repo)
| Area |
Files |
| VM builtins |
lib/VM/BuiltinClasses.php, new handlers under lib/VM/Builtin/ |
| Compiler |
No syntax change — static method calls on Closure |
| JIT/AOT |
VM-first; JIT static methods on builtin class phase 2 |
| Tests |
test/compliance/cases/language/closure_from_callable.phpt, closure_bind_to.phpt |
Done when
Labels
language, implementation-ready
Category
languageProblem
Closure::fromCallable()andClosure::bindTo()are not available on the VM builtinClosureclass. PHP 7.1+ code usesfromCallablefor first-class callables;bindTorebinding is distinct fromClosure::bind()tracked in #3097.php-src reference
Zend/zend_closures.c—zend_closure_from_callable,zend_closure_bind_toext/standard/basic_functions.c— userland exposureRepro (today)
bindTo repro
Scope (this repo)
lib/VM/BuiltinClasses.php, new handlers underlib/VM/Builtin/Closuretest/compliance/cases/language/closure_from_callable.phpt,closure_bind_to.phptDone when
Closure::fromCallable('strlen')returns invokable equivalent tostrlenunder VMClosure::fromCallable([$obj, 'method'])respects visibility like ZendbindTo($newThis, $newScope)matches Zend scope semantics for private/protected accesscall_user_func*if callable is not yet implementedLabels
language,implementation-ready