[php-src] Issue #7942: Readonly properties mutable when assigning reference to them
| From: | ondrejmirtes | Date: | Fri, 14 Jan 2022 10:56:26 +0000 |
| Subject: | [php-src] Issue #7942: Readonly properties mutable when assigning reference to them | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-239005@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/7942
Author: ondrejmirtes
### Description
Readonly properties should not be mutable with any means, but the following code surprisingly works
(https://3v4l.org/qiDTk):
```php
<?php
class Foo
{
public readonly int $bar;
public function set(int &$i)
{
$this->bar = &$i;
}
}
$i = 1;
$foo = new Foo();
$foo->set($i);
$i = 20;
var_dump($foo->bar); // 20
```
Additionally, without the
& in int &$i, the property value stays
1 but does not report any error: https://3v4l.org/NMDAp
### PHP Version
PHP 8.1
### Operating System
_No response_