Skip to content

Language: class const new accepted under PROFILE=8.4 — Zend rejects (Zend/zend_compile.c) #21493

Description

@PurHur

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

  • Class const / property-default new fatals like Zend under default + PROFILE=8.4 (VM/JIT/AOT parse)
  • Param-default + static-var new still work
  • Compliance guard + repro exits non-zero / matches Zend message
  • php-src-strict

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:compilerCompiler / CFG / JITbugSomething isn't workingimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-2:languagePhase 2 – language features

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions