Description
Readonly properties should not be mutable with any means, but the following code surprisingly works (https://3v4l.org/qiDTk):
<?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
Description
Readonly properties should not be mutable with any means, but the following code surprisingly works (https://3v4l.org/qiDTk):
Additionally, without the
&inint &$i, the property value stays1but does not report any error: https://3v4l.org/NMDApPHP Version
PHP 8.1
Operating System
No response