Category
language · php-src-strict
Problem
#9715 tracks enum cases as defaults for parameters and instance properties. The same compile failure hits static typed properties:
enum G: string { case X = 'x'; }
class C { public static G $g = G::X; }
VM parse/compile fails: Cannot use string as default value for property C::$g of type G — enum case lowered to backing scalar during default validation.
Zend accepts the default and C::$g reads as an enum case object.
php-src reference
Repro (failure today)
Save as test/repro/maintainer_gap_static_enum_default.php:
<?php
declare(strict_types=1);
enum G: string { case X = 'x'; }
class C {
public static G $g = G::X;
}
echo C::$g->name, "\n";
php test/repro/maintainer_gap_static_enum_default.php
# Zend: x
./script/docker-exec.sh php bin/vm.php test/repro/maintainer_gap_static_enum_default.php
# VM: compile error — Cannot use string as default value...
Scope
| Path |
Work |
lib/Compiler.php |
treat enum case defaults like other constant expressions for static properties |
lib/VM.php |
static property default materialization preserves enum case objects |
| Same fix as #9715 |
share one code path for param / instance / static defaults |
Done when
Related
Category
language· php-src-strictProblem
#9715 tracks enum cases as defaults for parameters and instance properties. The same compile failure hits static typed properties:
VM parse/compile fails:
Cannot use string as default value for property C::$g of type G— enum case lowered to backing scalar during default validation.Zend accepts the default and
C::$greads as an enum case object.php-src reference
Zend/zend_compile.c— static property default validation with enum type hintsZend/zend_enum.c— enum case as constant expressionRepro (failure today)
Save as
test/repro/maintainer_gap_static_enum_default.php:Scope
lib/Compiler.phplib/VM.phpDone when
xon VM./script/ci-fast.sh --filter static_enum_defaultgreenRelated