Closed
Description
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