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
Related
Category
language· php-src-strict · regressionProblem
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 throwsMethod call on non-objectinstead of running the enum method body.Distinct from enum static methods and first-class callable issues (#9758, #6845).
php-src reference
Zend/zend_enum.c— enum object handlers, method tableZend/zend_execute.c—ZEND_INIT_METHOD_CALLon enum casestest/compliance/cases/language/enum_user_method.phpt(Language: enum user methods — parse + VM dispatch (Zend zend_enum.c parity) #3390)Repro (failure today)
test/repro/maintainer_gap_enum_instance_method.php:test/repro/maintainer_gap_enum_case_method_dispatch.php(interface impl):E::A->label()enum_user_method.phptAOk/ErrMethod call on non-object❌Scope (this repo)
lib/VM.php$thisfor instance method dispatchlib/JIT/enum_user_method.phpt; addenum_case_interface_method.phptPHP-in-PHP: enum method dispatch in VM/JIT PHP; no new enum vtables in
runtime/.Done when
enum_user_method.phptgreen on VM + JIT where applicable./script/ci-fast.sh --filter enum_user_methodgreenRelated