Category
bootstrap | language
Problem
Any backed enum whose cases declare an explicit scalar (enum E: int { case A = 1; }) fails at compile time with CompileFatal: Enum case E::A must have a value, even though Zend accepts the source. This blocks essentially all backed-enum language and stdlib work (serialization, gettype(), BackedEnum::from(), etc.) on bin/vm.php.
Root cause: EnumBackedCaseCheck (lib/Compiler/EnumBackedCaseCheck.php) relies on php-cfg marking explicit values via enumCaseHasExplicitValue and/or a non-empty valueBlock. When script/apply-patches.sh has not synced the #5397 overlay into vendor/ircmaxell/php-cfg, both signals are absent for case A = 1, so the check misfires.
php-src reference
- php/php-src
Zend/zend_compile.c — zend_compile_enum_case (backed cases require explicit or auto value)
- Overlay:
patches/overlays/php-cfg/enum-parser-methods.php, script/apply-patches.sh (apply_php_cfg_enum_class_const_overlay)
Repro (failure today)
<?php
enum E: int {
case A = 1;
}
echo E::A->value, "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php repro.php # 1
php bin/vm.php repro.php 2>&1 # CompileFatal: Enum case E::A must have a value
'
| Runtime |
Result |
| Zend PHP 8.x |
1 |
bin/vm.php |
CompileFatal before execution |
String-backed enum E: string { case A = 'x'; } fails the same way when overlay is missing.
Scope (this repo)
| Module |
Path |
| Compiler guard |
lib/Compiler/EnumBackedCaseCheck.php — treat explicit = expr via valueBlock children or require overlay in Docker/CI |
| Patches |
script/apply-patches.sh — fail loudly if #5397 overlay not applied; run in docker-exec image build |
| Tests |
extend test/unit/EnumBackedCaseCheckTest.php; compliance test/compliance/cases/language/enum_backed_int_value.phpt |
Prefer defensive check (inspect valueBlock) so tar-copy Docker without re-patched vendor still compiles backed enums.
Done when
Verification
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter EnumBackedCaseCheck'
Related
Category
bootstrap|languageProblem
Any backed enum whose cases declare an explicit scalar (
enum E: int { case A = 1; }) fails at compile time withCompileFatal: Enum case E::A must have a value, even though Zend accepts the source. This blocks essentially all backed-enum language and stdlib work (serialization,gettype(),BackedEnum::from(), etc.) onbin/vm.php.Root cause:
EnumBackedCaseCheck(lib/Compiler/EnumBackedCaseCheck.php) relies on php-cfg marking explicit values viaenumCaseHasExplicitValueand/or a non-emptyvalueBlock. Whenscript/apply-patches.shhas not synced the#5397overlay intovendor/ircmaxell/php-cfg, both signals are absent forcase A = 1, so the check misfires.php-src reference
Zend/zend_compile.c—zend_compile_enum_case(backed cases require explicit or auto value)patches/overlays/php-cfg/enum-parser-methods.php,script/apply-patches.sh(apply_php_cfg_enum_class_const_overlay)Repro (failure today)
1bin/vm.phpString-backed
enum E: string { case A = 'x'; }fails the same way when overlay is missing.Scope (this repo)
lib/Compiler/EnumBackedCaseCheck.php— treat explicit= exprviavalueBlockchildren or require overlay in Docker/CIscript/apply-patches.sh— fail loudly if#5397overlay not applied; run indocker-execimage buildtest/unit/EnumBackedCaseCheckTest.php; compliancetest/compliance/cases/language/enum_backed_int_value.phptPrefer defensive check (inspect
valueBlock) so tar-copy Docker without re-patched vendor still compiles backed enums.Done when
1on VM inphp-compiler:22.04-devwithout manual patch stepsEnumBackedCaseCheckTest::testBackedEnumCaseWithValueCompilespasses in Docker CI#5397PHPT)Verification
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter EnumBackedCaseCheck'Related
listSpreadRhsoverlay noise