Skip to content

A readonly property initialised through a dynamic-name store can be initialised again by the constructor (Zend: Error "Cannot modify readonly property Ro::$x") #471

Closed

Description

@blacktrs

Summary

A readonly property initialised through a dynamic-name store can be initialised again by the constructor (Zend: Error "Cannot modify readonly property Ro::$x").

Repro

<?php
class Ro { public function __construct(public readonly string $x = 'init') {} }
$o = (new ReflectionClass('Ro'))->newInstanceWithoutConstructor();
$set = \Closure::bind(function (string $k, string $v): void { $this->$k = $v; }, $o, 'Ro');
$set('x', 'a');
try { $o->__construct(); echo $o->x, "\n"; } catch (Throwable $e) { echo get_class($e), ': ', $e->getMessage(), "\n"; }

Expected (php)

Error: Cannot modify readonly property Ro::$x

Actual (manticore d1ecb013, Darwin arm64)


[exit code 255]
PHP Fatal error:  Uncaught Error: Using $this when not in object context

Tracking

Known-bug repro: tests/aot/repro/wrong/readonly_property_reinitialised_through_dynamic_store.php — bash tests/aot/xfail.sh -k readonly_property_reinitialised_through_dynamic_store reports XFAIL while this is open and XPASS once it is fixed; then move the repro into tests/aot/cases/ and close this issue.

Activity

  1. added
    bug
    wrong-answer
    on Oct 25, 2026
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

    bugwrong-answer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions