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.
<?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";
}
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
Expected (Zend/php-src)
Erroron the write to$c->x(message matches php-src closely enough for compliance).Actual (php-compiler)
php-src reference
Zend/zend_compile.c(readonly class flagging,ZEND_ACC_READONLY_CLASS)Zend/zend_object_handlers.c(property write restrictions)ext/reflection/php_reflection.c(ties intoReflectionClass::isReadOnly()Stdlib: ReflectionClass::isReadOnly() — missing on readonly classes (ext/reflection/php_reflection.c) #5221)Scope (this repo)
Done when
Erroron second assignment under VM (php-src-strict).