Category
Language · php-src-strict · illegal new in class constant (Pillar 4)
Problem
Under PHP_COMPILER_PROFILE=8.4, public const X = new stdClass; compiles and evaluates. Zend 8.4.23 (and 8.2) reject at compile time: Fatal error: New expressions are not supported in this context. Parameter defaults / static-variable new remain legal on both sides — only class constants (and property defaults) must stay forbidden.
Probed 2026-07-20 vs php:8.4-cli (8.4.23) and PHP_COMPILER_PROFILE=8.4 php bin/vm.php.
| Repro |
Zend 8.4.23 |
VM PROFILE=8.4 |
class A { public const X = new stdClass; } |
Fatal: New expressions are not supported in this context |
compiles → object ❌ |
function f($x = new stdClass){} |
OK |
OK |
function g(){ static $x = new stdClass; } |
OK |
OK |
Snapshot #9978 mentioned class-const new; this is the concrete child issue.
php-src reference
- php/php-src
Zend/zend_compile.c — const-expr new reject (zend_compile_const_expr)
- PHP 8.1 “new in initializers” RFC — allows param/static-var/attribute defaults, not class constants or property defaults
PHP implementation target
lib/Compiler/NewWithoutParensCompileCheck.php (and related const-expr compile path) — keep reject on class const / property default for all profiles including forward 8.4
- No new C
Repro
./script/docker-exec.sh -- bash -lc 'export PHP_COMPILER_PROFILE=8.4
printf "%s\n" "<?php class A { public const X = new stdClass; } echo gettype(A::X);" > /tmp/c.php
php bin/vm.php /tmp/c.php; echo exit:$?
# expect compile fatal matching Zend
'
Done when
Related
Category
Language· php-src-strict · illegalnewin class constant (Pillar 4)Problem
Under
PHP_COMPILER_PROFILE=8.4,public const X = new stdClass;compiles and evaluates. Zend 8.4.23 (and 8.2) reject at compile time:Fatal error: New expressions are not supported in this context. Parameter defaults / static-variablenewremain legal on both sides — only class constants (and property defaults) must stay forbidden.Probed 2026-07-20 vs
php:8.4-cli(8.4.23) andPHP_COMPILER_PROFILE=8.4 php bin/vm.php.class A { public const X = new stdClass; }object❌function f($x = new stdClass){}function g(){ static $x = new stdClass; }Snapshot
#9978mentioned class-constnew; this is the concrete child issue.php-src reference
Zend/zend_compile.c— const-exprnewreject (zend_compile_const_expr)PHP implementation target
lib/Compiler/NewWithoutParensCompileCheck.php(and related const-expr compile path) — keep reject on class const / property default for all profiles including forward 8.4Repro
Done when
newfatals like Zend under default + PROFILE=8.4 (VM/JIT/AOT parse)newstill workRelated
#9978