Skip to content

Language: clone with syntax (clone($obj, ['prop'])) — parse fails despite runtime support (PHP 8.4, Zend/zend_language_parser.y) #9743

Closed

Description

@PurHur

Category

language · php-src-strict

Problem

PHP 8.4 clone($object, ['prop', ...]) (clone-with) lets callers reinitialize selected properties on a cloned object — notably readonly properties that would otherwise stay frozen after clone.

This compiler already has runtime support (lib/VM/CloneWithSupport.php, lib/JIT/Builtin/CloneWithReinitRuntime.php, ext/standard/CloneWithJitHelper.php, issue #9717 for AOT LLVM routing), but the parser rejects the syntax before compile:

Syntax error, unexpected ',' on line N

Workers cannot exercise clone-with end-to-end until parse + compile lowering accept the second argument.

php-src reference

Repro (failure today)

Save as test/repro/maintainer_gap_clone_with_syntax.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, ['a']);
echo $w2->a, ',', $w2->b, "\n";
php test/repro/maintainer_gap_clone_with_syntax.php
# Zend PHP 8.4+: 1,2  (readonly b copied; a reinitialized)

./script/docker-exec.sh php bin/vm.php test/repro/maintainer_gap_clone_with_syntax.php
# VM: PhpParser Syntax error, unexpected ',' — parse fails

Scope (PHP-in-PHP first)

Path Work
vendor/nikic/php-parser / php-cfg overlay accept clone($x, ['prop']) AST node (may need grammar patch via patches/)
lib/Compiler.php emit clone-with property list + hook existing CloneWithSupport
lib/VM.php wire reinit window (already partially present)
lib/JIT/ reuse CloneWithReinitRuntime / CloneWithJitHelper
test/compliance/cases/language/clone_with_readonly.phpt readonly reinit parity

Do not add new C in runtime/ — reuse existing PHP helpers (#9717).

Done when

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 18, 2026
  2. PurHur commented on Jun 18, 2026

    @PurHur
    OwnerAuthor

    claim: worker-lane-b — starting this run

  3. PurHur commented on Jun 18, 2026

    @PurHur
    OwnerAuthor

    Merged via #9757.

    Verification:

    ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
    php bin/vm.php test/repro/maintainer_gap_clone_with_syntax.php
    php vendor/bin/phpunit test/unit/CloneWithTest.php
    php vendor/bin/phpunit --filter clone_with test/compliance/VMTest.php
    '

    Repro prints 1,2; unit + VM compliance green.

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

    IMPORTANTCritical patharea: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