The following code snippet will produce an error on PHP 8.2:
<?php
const foo = new stdClass();
foo->bar = 'baz';
echo foo->bar;
?>
I would expect that an error would not occur, since I am assigning to the prop rather than trying to reassign the constant.
If I create a new class, extending stdClass, and add the following method:
class extendsStdClass extends stdClass {
public function set(string $name, mixed $value) {
$this->$name = $value;
}
}
then I can assign to props using the following syntax:
<?php
const foo = new extendsStdClass();
foo->set('bar', 'baz');
echo foo->bar;
?>
but, the linter will not recognize props being set in this way, nor provide any type hinting:
Undefined property: extendsStdClass::$bar
Is there some reason we are not able to write to props on a class instance that is defined as a constant?