Skip to content

Language: clone() on readonly objects — deep copy + readonly property guards (Zend zend_clones.c parity) #3430

Closed

Description

@PurHur

Category

language

Problem

clone $obj today uses ObjectEntry::cloneShallow() (lib/VM/ObjectEntry.php) — copies property values but does not implement Zend rules for:

php-src reference

  • Zend/zend_clones.c — zend_clone_obj, readonly clone restrictions
  • Zend/zend_object_handlers.c — clone_obj handler, property separation
  • Zend/zend_compile.c — ZEND_CLONE opcode

Repro

<?php
readonly class Box {
    public function __construct(public string $v) {}
}
$a = new Box('a');
$b = clone $a;
$b->v = 'b'; // Zend: Error Cannot modify readonly property
echo $b->v;
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php repro.php'
php repro.php

Zend: third line throws on $b->v = 'b'. This compiler: verify clone creates independent object and readonly write still fatal.

Scope

Done when

  • Repro: modifying clone of readonly property fatals like Zend
  • Non-readonly classes: clone is independent copy (nested array copy subset documented if deferred)
  • ./script/ci-fast.sh --filter clone_readonly 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 May 29, 2026
  2. PurHur commented on May 30, 2026

    @PurHur
    OwnerAuthor

    claim: worker-lane-c — starting this run

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