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

30 lines
461 B
PHP

--TEST--
By-ref foreach over readonly property
--FILE--
<?php
class Test {
public readonly int $prop;
public function init() {
$this->prop = 1;
}
}
$test = new Test;
// Okay, as foreach skips over uninitialized properties.
foreach ($test as &$prop) {}
$test->init();
try {
foreach ($test as &$prop) {}
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
Cannot acquire reference to readonly property Test::$prop