Skip to content

Language: Closure::fromCallable() and Closure::bindTo() (Zend zend_closures.c parity) #3266

Description

@PurHur

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

Activity

  1. added
    enhancementNew feature or request
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on May 29, 2026
  2. PurHur commented on May 29, 2026

    @PurHur
    OwnerAuthor

    claim: worker-lane-c — starting this run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-2:languagePhase 2 – language features

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions