1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00
Files
archived-php-src/Zend/tests/readonly_props/visibility_change.phpt
Nikita Popov 6780aaa532 Implement readonly properties
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.
2021-07-20 12:05:46 +02:00

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)