Category
language
Problem
PHP 8.1+ allows enums to implement interfaces (enum Foo: string implements Bar { ... }). This compiler crashes during php-cfg parse when implements is present on an enum:
TypeError: PHPCfg\Op\Stmt\Enum_::__construct(): Argument #3 ($implements) must be of type array, PHPCfg\Block given
The vendor php-cfg Enum_ opcode and Parser::parseStmt_Enum() do not wire interface lists correctly (similar to class implements handling).
php-src reference
Zend/zend_enum.c — zend_register_enum, interface implementation on enum entries
Zend/zend_compile.c — zend_compile_enum implements-clause validation
ext/reflection/php_reflection.c — ReflectionEnum::implements() metadata
Repro (today)
<?php
interface HasName { public function label(): string; }
enum Status: string implements HasName {
case Open = 'open';
case Closed = 'closed';
public function label(): string { return $this->name; }
}
echo Status::Open->label(), "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php repro.php'
/usr/bin/php repro.php # Zend: Open
This compiler: fatal in php-cfg Parser.php before VM runs.
Scope (this repo)
| Module |
Path |
| php-cfg |
vendor patch or fork: PHPCfg/Parser.php parseStmt_Enum() — pass interface name list to Enum_ |
| Compiler |
store implements on enum class entry like user classes |
| VM |
instanceof / interface checks on enum instances |
| Tests |
test/compliance/cases/language/enum_implements_interface.phpt |
Done when
Related
Category
languageProblem
PHP 8.1+ allows enums to implement interfaces (
enum Foo: string implements Bar { ... }). This compiler crashes during php-cfg parse whenimplementsis present on an enum:The vendor php-cfg
Enum_opcode andParser::parseStmt_Enum()do not wire interface lists correctly (similar to classimplementshandling).php-src reference
Zend/zend_enum.c—zend_register_enum, interface implementation on enum entriesZend/zend_compile.c—zend_compile_enumimplements-clause validationext/reflection/php_reflection.c—ReflectionEnum::implements()metadataRepro (today)
This compiler: fatal in php-cfg
Parser.phpbefore VM runs.Scope (this repo)
PHPCfg/Parser.phpparseStmt_Enum()— pass interface name list toEnum_implementson enum class entry like user classesinstanceof/ interface checks on enum instancestest/compliance/cases/language/enum_implements_interface.phptDone when
Openon VMStatus::Open instanceof HasNameis trueimplementsunchanged (Language: Enum declarations (enum / backed enum) #1356 regression guard)docs/capabilities-syntax.mdRelated
BackedEnum::from()/tryFrom()UnitEnum::cases()