Skip to content

Language: clone $obj with ['prop'] keyword array syntax — parse fails (PHP 8.4, Zend/zend_language_parser.y) #9995

Closed

Description

@PurHur

Category

language · php-src-strict · PHP 8.4

Problem

PHP 8.4 supports clone-with using an array property list in two equivalent forms:

Runtime support exists (lib/VM/CloneWithSupport.php, CloneWithJitHelper.php) but the keyword + array form never reaches compile.

php-src reference

Repro (failure today)

Committed: test/repro/maintainer_probe_clone_with_keyword.php

<?php
declare(strict_types=1);

class W {
    public int $a = 1;
    public readonly int $b;

    public function __construct() {
        $this->b = 2;
    }
}

$w = new W();
$w2 = clone $w with ['a'];
echo $w2->a, ',', $w2->b, "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php test/repro/maintainer_probe_clone_with_keyword.php'
# PhpParser: Syntax error, unexpected identifier "with"

Control (passes): test/repro/maintainer_gap_clone_with_syntax.php — clone($w, ['a']) prints 1,2.

Scope (PHP-in-PHP first)

Path Work
lib/Ast/CloneWithDesugar.php extend findCloneWithSpan() to accept [...] after with (not only {...} blocks)
vendor/nikic/php-parser / patches if grammar still rejects with keyword, patch overlay per #9743
lib/VM/CloneWithSupport.php reuse existing reinit window (no new C)
Tests compliance PHPT mirroring maintainer_probe_clone_with_keyword.php

Done when

  • Keyword form compiles and prints 1,2 on VM (php-src-strict)
  • Readonly properties outside the list stay immutable after clone
  • Existing clone($obj, [...]) desugar path stays green
  • ./script/ci-fast.sh --filter clone_with green

Related

Activity

  1. added
    enhancementNew feature or request
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jun 19, 2026
  2. PurHur commented on Jun 19, 2026

    @PurHur
    OwnerAuthor

    claim: worker-lane-c — starting this run

  3. PurHur commented on Jun 19, 2026

    @PurHur
    OwnerAuthor

    Merged via #10036.

    Fix: CloneWithDesugar::findCloneWithSpan() now accepts clone $obj with ['prop', ...] array property lists (PHP 8.4), reusing the same IIFE lowering as clone($obj, [...]).

    Verification:

    source script/php-env.sh
    php bin/vm.php test/repro/maintainer_probe_clone_with_keyword.php   # 1,2
    php bin/vm.php test/compliance/cases/language/clone_with_keyword_array.phpt   # 1,2
    ./vendor/bin/phpunit test/unit/CloneWithTest.php   # OK (12 tests)
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 machineenhancementNew 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