Description
The following code:
<?php
const a = new stdClass;
a->b = 42;
var_dump(a);
Resulted in this output:
Fatal error: Cannot use temporary expression in write context in /tmp/preview on line 3
But I expected this output instead:
object(stdClass)#1 (1) {
["b"]=>
int(42)
}
(The issue also arises for objects stored in class constants.)
A workaround is to use a temp variable (because a temporary variable is not a “temporary expression”, eh):
<?php
const a = new stdClass;
$_ = a;
$_->b = 42;
var_dump(a); // it works
Another workaround is to use a function returning the value of the constant:
<?php
const a = new stdClass;
constant('a')->b = 42;
var_dump(a); // it works
PHP Version
PHP 8.2
Operating System
No response
Description
The following code:
Resulted in this output:
But I expected this output instead:
(The issue also arises for objects stored in class constants.)
A workaround is to use a temp variable (because a temporary variable is not a “temporary expression”, eh):
Another workaround is to use a function returning the value of the constant:
PHP Version
PHP 8.2
Operating System
No response