Skip to content

Language: Closure::fromCallable([EnumCase, 'method']) treats case name as class (should call method on enum case object) #9039

Description

@PurHur

Category

language · php-src-strict

Problem

Closure::fromCallable([E::A, 'm']) must treat the first element as an object (the enum case instance) and create an object-method callable.

Today it resolves the enum case name as a class-string and fails with Class 'A' not found.

php-src reference

  • Zend/zend_closures.c — Closure::fromCallable
  • Zend/zend_API.c / Zend/zend_execute_API.c — callable resolution for [object, "method"]
  • Zend/zend_enum.c — enum case objects

Repro

<?php
enum E {
    case A;
    public function m(): void { echo "ok\n"; }
}

$c = Closure::fromCallable([E::A, 'm']);
$c();

Commands

# Zend
php repro.php

# This compiler
php bin/vm.php repro.php

Expected (Zend)

Prints:

ok

Actual (VM today)

Fatal LogicException: Closure::fromCallable(): Class 'A' not found.

Scope (this repo)

  • Callable normalization / resolution for array-callables where element 0 is an enum case object
  • Ensure no enum-case-to-string coercion occurs on [object, method] paths

Done when

  • Repro prints ok under php bin/vm.php
  • Additional guard: [E::class, 'm'] still resolves as class-method callable, while [E::A, 'm'] is object-method
  • Add compliance coverage: test/compliance/cases/language/closure_from_callable_enum_case_object_method.phpt

Activity

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

    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions