Skip to content

Language: clone-with syntax clone($obj, ['prop']) — parse + selective reinit missing (PHP 8.5, Zend/zend_language_parser.y) #9803

Description

@PurHur

Category

language · php-src-strict

Problem

PHP 8.5 adds clone-with syntax: clone($object, ['prop1', 'prop2']) clones $object and re-initializes only the listed properties from the source (see RFC / php-src clone grammar extension).

This compiler accepts a plain clone $obj but does not parse parenthesized clone-with:

$w2 = clone($w, ['a']); // Zend: selective reinit; VM today: parse error OR wrong lowering

Maintainer repro (test/repro/maintainer_gap_clone_with_syntax.php) shows VM prints 1,2 while Zend rejects with parse error on the comma form — grammar/lowering for clone-with is missing.

php-src reference

Repro

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php test/repro/maintainer_gap_clone_with_syntax.php 2>&1 | head -3
php test/repro/maintainer_gap_clone_with_syntax.php 2>&1 | head -3
'
Runtime Result
Zend PHP 8.5+ Parses clone-with; reinit listed props only
bin/vm.php (today) Wrong — legacy clone path or parse failure

Scope (this repo) — PHP-in-PHP first

Layer Path
Parser php-cfg / lib/SourcePreprocessor/ — clone ( … , [ … ])
Compiler lib/Compiler.php — lower to clone + property reinit op sequence
VM lib/VM.php — selective property copy from source
JIT/AOT reuse clone lowering; follow CloneWithJitHelper (#9717) when emit-helper path exists
Tests new test/compliance/cases/language/clone_with_basic.phpt

No new C runtime branches — clone-with is compile-time sugar + VM object copy.

Done when

  • Repro compiles on VM and output matches Zend PHP 8.5+ for selective reinit
  • readonly props in reinit list follow php-src rules
  • JIT/AOT agree with VM on repro (or documented follow-up)
  • ./script/ci-fast.sh --filter clone_with green

Related

Activity

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