Skip to content

Regression: enum case instance method call — re-#3390, Method call on non-object (Zend/zend_enum.c) #10341

Description

@PurHur

Category

language · php-src-strict · regression

Problem

Calling an instance method on an enum case (Status::Ok->label(), E2::A->foo() on interface method) must dispatch like Zend. Closed #3390 added parse + VM dispatch, but compliance is red again: VM throws Method call on non-object instead of running the enum method body.

Distinct from enum static methods and first-class callable issues (#9758, #6845).

php-src reference

Repro (failure today)

test/repro/maintainer_gap_enum_instance_method.php:

<?php
enum E: string {
    case A = 'a';
    public function label(): string { return $this->name; }
}
try {
    echo E::A->label(), "\n";
} catch (Throwable $e) {
    echo get_class($e), ': ', $e->getMessage(), "\n";
}

test/repro/maintainer_gap_enum_case_method_dispatch.php (interface impl):

<?php
enum E { case A; public function m(): string { return 'x'; } }
interface I { public function foo(): void; }
enum E2 implements I {
    case A;
    public function foo(): void { echo "ok\n"; }
}
echo E::A->m(), "\n";
E2::A->foo();
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php test/repro/maintainer_gap_enum_instance_method.php
php bin/vm.php test/repro/maintainer_gap_enum_instance_method.php
php bin/vm.php test/compliance/cases/language/enum_user_method.phpt
'
Runtime E::A->label() enum_user_method.phpt
Zend PHP 8.1+ A Ok / Err
VM today Method call on non-object ❌ same fatal ❌

Scope (this repo)

Path Work
lib/VM.php enum case as $this for instance method dispatch
lib/JIT/ mirror enum method calls when JIT enum objects enabled
Tests restore enum_user_method.phpt; add enum_case_interface_method.phpt

PHP-in-PHP: enum method dispatch in VM/JIT PHP; no new enum vtables in runtime/.

Done when

  • Both repro scripts match Zend output on VM
  • enum_user_method.phpt green on VM + JIT where applicable
  • Static enum methods unchanged
  • ./script/ci-fast.sh --filter enum_user_method green

Related

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

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions