mirror of
https://github.com/php/php-src.git
synced 2024-09-22 02:17:32 +00:00
6780aaa532
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.
27 lines
429 B
PHP
27 lines
429 B
PHP
--TEST--
|
|
Can override readonly property with attributes
|
|
--FILE--
|
|
<?php
|
|
|
|
#[Attribute]
|
|
class FooAttribute {}
|
|
|
|
class A {
|
|
public readonly int $prop;
|
|
|
|
public function __construct() {
|
|
$this->prop = 42;
|
|
}
|
|
}
|
|
class B extends A {
|
|
#[FooAttribute]
|
|
public readonly int $prop;
|
|
}
|
|
|
|
var_dump((new ReflectionProperty(B::class, 'prop'))->getAttributes()[0]->newInstance());
|
|
|
|
?>
|
|
--EXPECT--
|
|
object(FooAttribute)#1 (0) {
|
|
}
|