Skip to content

Language: clone with partial property list (PHP 8.4) — syntax + readonly reinit semantics (Zend/zend_clones.c) #10310

Closed

Description

@PurHur

Category

language · php-src-strict · PHP 8.4

Problem

PHP 8.4 adds clone($obj, ['prop', ...]) to reinitialize selected properties (notably readonly properties) on the clone. This compiler accepts the syntax on the 8.4 target and executes, but parity vs php-src is unverified:

Workers need language semantics: which properties re-run default/constructor init, readonly rules, and whether the source object is mutated.

php-src reference

Repro

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";

Extended state check (add to repro or compliance test):

var_export([$w->a, $w->b, $w2->a, $w2->b]);
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php test/repro/maintainer_gap_clone_with_syntax.php
'

Compare against php-src 8.4 Zend build or upstream Zend/tests/clones/clone_with*.phpt when available.

Scope (PHP-in-PHP)

Layer Path
Compiler lib/Compiler.php — clone with property list AST
VM clone opcode + readonly reinit (lib/VM.php, CloneWithSupport)
JIT #10002 CloneWithReinitRuntime — shrink after VM SSOT
Tests test/compliance/cases/language/clone_with_readonly.phpt

Done when (php-src-strict)

  • Repro output matches php-src 8.4 Zend for $w2 property values
  • Source $w object state matches Zend (no spurious mutation)
  • Invalid property names in list throw/errors per Zend
  • ./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 20, 2026
  2. PurHur commented on Jun 20, 2026

    @PurHur
    OwnerAuthor

    claim: cursor-agent-lane-c — starting this run (clone-with property list reinit semantics)

  3. PurHur commented on Jun 20, 2026

    @PurHur
    OwnerAuthor

    Merged via #10371.

    Fix: Property-list clone-with entries without explicit values (clone($w, ['a'])) now reinitialize to declared defaults instead of copying the source object's current values.

    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 --filter CloneWithTest
    php vendor/bin/phpunit --filter clone_with_reinit
    '
    • Repro: array (0 => 99, 1 => 2, 2 => 1, 3 => 2) — source unchanged, clone reinit to default a=1
    • CloneWithTest: 14/14 OK
    • clone_with_reinit compliance: VM + JIT OK
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:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-2:languagePhase 2 – language featuresstdlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions