Self-host and modern library code targeting PHP 8.4 cannot compile.
<?php
class C {
public static string|int $p = 'x';
}
echo C::$p, "\n";
C::$p = 42;
echo C::$p, "\n";
try {
C::$p = 3.14;
} catch (TypeError $e) {
echo 'TypeError: ', $e->getMessage(), "\n";
}
Category
languageProblem
PHP 8.4 allows union types on static properties (e.g.
public static string|int $p = 0;). php-src parses and enforces these viazend_compile.c/ typed-property handlers. This compiler rejects the syntax with a parse error (unexpected '|', expecting T_AMPERSAND…) or fails later on DNF reconstruction.Self-host and modern library code targeting PHP 8.4 cannot compile.
php-src reference
Zend/zend_compile.c— static property type compilation (PHP 8.4)Zend/zend_types.c— union type reflection materializationZend/zend_inheritance.c— static property type compatibility in inheritanceRepro
test/repro/static_property_union_type.php:static string|int $pScope
lib/Compiler/TypeReconstructor.php(extend beyond instance DNF Language: DNF types — union of intersections (PHP 8.2) #3094)lib/Compiler/TypedPropertyCompileCheck.php(static branch)lib/VM.phpstatic property writes,lib/VM/TypedPropertyCheck.phplib/JIT/Builtin/Type/Object_.phpDone when
test/compliance/cases/language/static_property_union_type.phptgreen./script/ci-fast.sh --filter static_property_uniongreenLinks