Category
language
Problem
Plain enums with user-defined methods fail at parse/CFG time today. The php-cfg enum stmt constructor receives the methods block where $implements should be, so any enum body with methods crashes before VM lowering.
Distinct from #3373 (enum implements Interface); this ticket is enum methods on cases without interface lists.
php-src reference
Repro (failure today)
<?php
enum Status {
case Ok;
case Err;
public function label(): string {
return $this->name;
}
}
echo Status::Ok->label(), "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php repro.php'
# TypeError in PHPCfg\Op\Stmt\Enum_::__construct(): Argument #3 ($implements) must be of type array, PHPCfg\Block given
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php repro.php'
# Ok / Err labels on Zend PHP 8.1+
Scope
| Module |
Path |
| Parser / CFG |
vendor/ircmaxell/php-cfg enum stmt + patch in patches/ if needed |
| Compiler |
lib/Compiler.php enum lowering |
| VM |
lib/VM.php enum case object method dispatch |
| Tests |
test/compliance/cases/language/enum_user_method.phpt |
Done when
Notes
Category
languageProblem
Plain enums with user-defined methods fail at parse/CFG time today. The php-cfg enum stmt constructor receives the methods block where
$implementsshould be, so any enum body with methods crashes before VM lowering.Distinct from #3373 (enum
implements Interface); this ticket is enum methods on cases without interface lists.php-src reference
Zend/zend_enum.c— enum method table, case object handlersZend/zend_compile.c—zend_compile_enum/ method registrationRepro (failure today)
Scope
vendor/ircmaxell/php-cfgenum stmt + patch inpatches/if neededlib/Compiler.phpenum loweringlib/VM.phpenum case object method dispatchtest/compliance/cases/language/enum_user_method.phptDone when
$case->method()dispatches like Zend (no dynamic$thismutation of case identity)Notes