Category
language
Problem
Zend treats E::Case->value (and similar enum-case member fetches) as a compile-time constant for default values of properties, static properties, and parameters. This compiler rejects them with #3803 ("Property/Parameter default must be a compile-time constant") even though the same expression works in const G = E::A->value; at file scope.
Blocks idiomatic PHP 8.1+ defaults that mirror backing values without magic numbers.
php-src reference
Repro (failure today)
<?php
enum E: int { case A = 1; }
class C {
public int $n = E::A->value; // compile error VM; Zend OK
public static int $s = E::A->value; // compile error VM; Zend OK
}
function f(int $n = E::A->value): int { return $n; } // compile error VM; Zend OK
var_dump((new C())->n, C::$s, f());
docker info >/dev/null
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php test/repro/maintainer_enum_value_property_default.php # parseAndCompile #3803
php bin/vm.php test/repro/maintainer_static_default_enum_value.php
php bin/vm.php test/repro/maintainer_param_default_enum_value.php
/usr/bin/php test/repro/maintainer_param_default_enum_value.php # int(1)
'
| Form |
Zend |
VM |
const G = E::A->value; |
int(1) ✅ |
int(1) ✅ |
public int $n = E::A->value |
compiles |
#3803 fatal |
public static int $s = E::A->value |
compiles |
#3803 fatal |
function f($n = E::A->value) |
compiles |
#3803 fatal |
php-src-strict: unit enum cases without ->value remain compile errors; only backed-case ->value (and other Zend-allowed constant exprs) fold.
Scope (this repo)
| Layer |
Path |
| Compiler |
lib/Compiler.php — extend default-value folder for EnumCaseFetch->value |
| CFG |
constant expression evaluator shared with file-scope const |
| VM |
ensure default slots materialize before instance/static init |
| Tests |
test/compliance/cases/language/enum_case_value_default.phpt |
PHP-in-PHP: fold in compiler — no C runtime default tables.
Done when
Related
Category
languageProblem
Zend treats
E::Case->value(and similar enum-case member fetches) as a compile-time constant for default values of properties, static properties, and parameters. This compiler rejects them with#3803("Property/Parameter default must be a compile-time constant") even though the same expression works inconst G = E::A->value;at file scope.Blocks idiomatic PHP 8.1+ defaults that mirror backing values without magic numbers.
php-src reference
Zend/zend_compile.c—zend_compile_default_value(), enum case fetch in constant expressionsZend/zend_constants.c—ZVAL_LONG/ZVAL_STRINGfolding from backed enum casesZend/zend_enum.c—->valueon enum cases in constant contextRepro (failure today)
const G = E::A->value;int(1)✅int(1)✅public int $n = E::A->valuepublic static int $s = E::A->valuefunction f($n = E::A->value)php-src-strict: unit enum cases without
->valueremain compile errors; only backed-case->value(and other Zend-allowed constant exprs) fold.Scope (this repo)
lib/Compiler.php— extend default-value folder forEnumCaseFetch->valueconsttest/compliance/cases/language/enum_case_value_default.phptPHP-in-PHP: fold in compiler — no C runtime default tables.
Done when
int(1)on VME { case A; }with->valuedefault still compile-errors like Zend./script/ci-fast.sh --filter enum_case_value_defaultgreenRelated
self::/null defaults; this extends enum-case member accessnewexpression (PHP 8.3) — runtime init fails with null TypeError (zend_compile.c) #7375 —newexpression in property defaults (distinct form)