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/readonly_with_default.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

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