Skip to content

Language: readonly class semantics — property write restrictions must match php-src (Zend/zend_compile.c) #9064

Description

@PurHur

Category

language

Problem

Readonly classes (PHP 8.2) semantics are not implemented or diverge from php-src: readonly class C { ... } should implicitly make instance properties readonly and enforce write restrictions after initialization.

This is a language parity gap (not just reflection): user-visible writes must error like php-src.

Repro

<?php
readonly class C {
    public int $x;
    public function __construct(int $x) { $this->x = $x; }
}

$c = new C(1);
try {
    $c->x = 2;
    echo "NOERROR\n";
} catch (Throwable $e) {
    echo get_class($e), ": ", $e->getMessage(), "\n";
}

Expected (Zend/php-src)

  • Throws Error on the write to $c->x (message matches php-src closely enough for compliance).

Actual (php-compiler)

  • Write succeeds, wrong exception type, or message/behavior diverges.

php-src reference

Scope (this repo)

  • Parser/compiler: readonly class flag propagation to runtime class metadata.
  • VM property write path: enforce readonly class semantics and correct error type.

Done when

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

    area:vmVirtual machineimplementation-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