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.
20 lines
316 B
PHP
20 lines
316 B
PHP
--TEST--
|
|
Readonly property with default value
|
|
--FILE--
|
|
<?php
|
|
|
|
class Test {
|
|
public readonly int $prop = 1;
|
|
}
|
|
|
|
$test = new Test;
|
|
try {
|
|
$test->prop = 2;
|
|
} catch (Error $e) {
|
|
echo $e->getMessage(), "\n";
|
|
}
|
|
|
|
?>
|
|
--EXPECTF--
|
|
Fatal error: Readonly property Test::$prop cannot have default value in %s on line %d
|