mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Add support for readonly properties, for which only a single initializing assignment from the declaring scope is allowed. RFC: https://wiki.php.net/rfc/readonly_properties_v2 Closes GH-7089.
31 lines
446 B
PHP
31 lines
446 B
PHP
--TEST--
|
|
Visibility can change in readonly property
|
|
--FILE--
|
|
<?php
|
|
|
|
class A {
|
|
protected readonly int $prop;
|
|
|
|
public function __construct() {
|
|
$this->prop = 42;
|
|
}
|
|
}
|
|
class B extends A {
|
|
public readonly int $prop;
|
|
}
|
|
|
|
$a = new A();
|
|
try {
|
|
var_dump($a->prop);
|
|
} catch (Error $error) {
|
|
echo $error->getMessage() . "\n";
|
|
}
|
|
|
|
$b = new B();
|
|
var_dump($b->prop);
|
|
|
|
?>
|
|
--EXPECT--
|
|
Cannot access protected property A::$prop
|
|
int(42)
|