Skip to content

Language: new readonly class(...) constructor args — parse rejected (Zend/zend_compile.c, PHP 8.4) #17467

Closed

Description

@PurHur

Category

language · php-src-strict · PHP 8.4 readonly anonymous classes

Problem

PHP 8.4 allows instantiating a readonly anonymous class with constructor arguments: new readonly class(5) { public function __construct(public int $x) {} }. Zend compiles and runs this. This compiler rejects the source during parse/compile with a misleading fatal about curly-brace offset syntax.

Repro Zend 8.2+ (Docker) VM (2026-07-09)
new readonly class(5) { public function __construct(public int $x) {} } int(5) Fatal error: Array and string offset access syntax with curly braces is no longer supported

Non-readonly new class(5) { ... } already compiles on VM — only the readonly + argument-list combination is broken.

php-src reference

PHP implementation target

  • vendor/ircmaxell/php-cfg/lib/PHPCfg/Parser.php — parse new readonly class(...) without treating class( as legacy { offset syntax
  • lib/Compiler.php — lowering for readonly anonymous instantiation with argument list
  • Match existing readonly-anonymous paths (CompilerVersion::supportsReadonlyAnonymousClass())

Repro

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && export PHP_COMPILER_PROFILE=8.4 && php bin/vm.php test/repro/maintainer_gap_readonly_anonymous_ctor_args.php'

Done when

  • Repro prints 5 on VM with PHP_COMPILER_PROFILE=8.4
  • Compliance .phpt under test/compliance/cases/language/readonly_anonymous_ctor_args.phpt
  • php-src-strict; no php-compiler-strict shortcut

North star: #1492

Activity

  1. added
    bugSomething isn't working
    enhancementNew feature or request
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jul 9, 2026
  2. PurHur commented on Jul 9, 2026

    @PurHur
    OwnerAuthor

    claim: cursor-agent-lane-b — starting this run

  3. PurHur commented on Jul 9, 2026

    @PurHur
    OwnerAuthor

    claim: cursor-agent-lane-a — starting this run (lane A queue stale/green; language/compiler #17467)

  4. PurHur commented on Jul 9, 2026

    @PurHur
    OwnerAuthor

    Merged via #17474

    Root cause: CurlyBraceOffsetRejector exempted new class(...) ctor-arg ( from the legacy curly-brace offset fatal but not new readonly class(...), so the class-body { was misread as \$expr{offset}.

    Fix: Extend the anonymous-class ctor-args exemption to T_NEW + T_READONLY + T_CLASS.

    Verification (green):

    ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && export PHP_COMPILER_PROFILE=8.4 && php bin/vm.php test/repro/maintainer_gap_readonly_anonymous_ctor_args.php'
    # 5
    vendor/bin/phpunit test/unit/CurlyBraceOffsetRejectorTest.php --filter CurlyBraceOffsetRejector
    vendor/bin/phpunit test/compliance/VMTest.php --filter readonly_anonymous_ctor_args
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:compilerCompiler / CFG / JITarea:vmVirtual machinebugSomething isn't workingenhancementNew feature or requestimplementation-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