Category
language · php-src-strict
Problem
PHP 8.3+ allows new expressions in class constant initializers (e.g. public const X = new C(1);). This compiler rejects them at compile time with New expressions are not supported in this context, blocking PHP 8.3/8.4 parity and self-host code using immutable constant object graphs.
Mentioned in parity snapshot #9978 but lacks a dedicated claimable issue.
php-src reference
Repro (verified 2026-06-20)
test/repro/maintainer_gap_new_in_constant.php:
<?php
class C {
public function __construct(public int $n = 0) {}
}
class Holder {
public const X = new C(1);
}
var_dump(Holder::X->n);
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php test/repro/maintainer_gap_new_in_constant.php 2>&1 | head -3
'
| Runtime |
Result |
| Zend PHP 8.3+ |
int(1) |
php bin/vm.php |
parseAndCompile failure: New expressions are not supported in this context ❌ |
Scope (PHP-in-PHP first)
| Area |
Files |
| Parser/CFG |
lib/Parser.php, constant-expression allowlist |
| Compiler |
lib/Compiler.php — lower new in zend_compile_const_expr path |
| VM |
constant materialization for object constants |
| JIT |
lib/JIT/ClassConstFetchHelper.php if object constants need runtime box |
Done when
Links
Category
language· php-src-strictProblem
PHP 8.3+ allows
newexpressions in class constant initializers (e.g.public const X = new C(1);). This compiler rejects them at compile time withNew expressions are not supported in this context, blocking PHP 8.3/8.4 parity and self-host code using immutable constant object graphs.Mentioned in parity snapshot #9978 but lacks a dedicated claimable issue.
php-src reference
Zend/zend_compile.c—zend_compile_const_expr(),ZEND_AST_NEWin constant context (PHP 8.3+)Zend/zend_constants.c— object-typed class constants, serialization at compile timeRepro (verified 2026-06-20)
test/repro/maintainer_gap_new_in_constant.php:int(1)php bin/vm.phpparseAndCompile failure: New expressions are not supported in this context❌Scope (PHP-in-PHP first)
lib/Parser.php, constant-expression allowlistlib/Compiler.php— lowernewinzend_compile_const_exprpathlib/JIT/ClassConstFetchHelper.phpif object constants need runtime boxDone when
int(1)on VM (php-src-strict)Holder::Xis the same object identity across reads (Zend constant object semantics)newin non-constant contexts unchangedtest/compliance/cases/language/class_const_new_expression.phptguards regressionLinks