Category
language — php-src-strict compile-time enum case defaults
Problem
Typed property and static property defaults using an enum case singleton (Status::Active, Mode::On) fail at compile with Cannot use int/string as default value for property … of type E. Zend accepts the enum case expression and initializes the property to the enum object.
Regression of closed #5891 / #3803 — compliance guard test/compliance/cases/language/enum_property_default.phpt is red again.
php-src reference
Repro
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php test/compliance/cases/language/enum_property_default.phpt'
Minimal inline:
<?php
enum Status: string { case Active = 'active'; }
class Config { public static Status $state = Status::Active; }
class Device { public Status $mode = Status::Active; }
Zend: compiles; Config::$state and (new Device())->mode are enum objects.
This compiler (bin/vm.php):
parseAndCompile failure: Cannot use string as default value for property Config::$state of type Status
Scope (PHP-in-PHP)
lib/Compiler.php — property/static default validation for enum case operands
lib/JIT/Builtin/Type/Object_.php — static enum case property default lowering helpers
lib/VM/EnumCaseSupport.php — enum case singleton materialization for defaults
- Avoid new C runtime branches; reuse compile-time enum case registry from class const inits
Done when (php-src-strict)
php bin/vm.php test/compliance/cases/language/enum_property_default.phpt matches Zend (\Status::Active static-same, \Mode::On instance-same).
enum_property_default_jit.phpt green when JIT in scope.
- Backed int and string enums work for instance + static typed defaults.
Related
#5891 (closed), #7399 (enum ->value in defaults), #1492 self-host compile spine.
Category
language— php-src-strict compile-time enum case defaultsProblem
Typed property and static property defaults using an enum case singleton (
Status::Active,Mode::On) fail at compile withCannot use int/string as default value for property … of type E. Zend accepts the enum case expression and initializes the property to the enum object.Regression of closed #5891 / #3803 — compliance guard
test/compliance/cases/language/enum_property_default.phptis red again.php-src reference
zend_compile_const_expr()/ property default validation for enum zvalsRepro
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php test/compliance/cases/language/enum_property_default.phpt'Minimal inline:
Zend: compiles;
Config::$stateand(new Device())->modeare enum objects.This compiler (
bin/vm.php):Scope (PHP-in-PHP)
lib/Compiler.php— property/static default validation for enum case operandslib/JIT/Builtin/Type/Object_.php—static enum case property defaultlowering helperslib/VM/EnumCaseSupport.php— enum case singleton materialization for defaultsDone when (php-src-strict)
php bin/vm.php test/compliance/cases/language/enum_property_default.phptmatches Zend (\Status::Active static-same,\Mode::On instance-same).enum_property_default_jit.phptgreen when JIT in scope.Related
#5891 (closed), #7399 (enum
->valuein defaults), #1492 self-host compile spine.