Access property of object stored in a constant

From: Date: Fri, 18 Aug 2023 15:27:32 +0000
Subject: Access property of object stored in a constant
Groups: php.internals 
Request: Send a blank email to internals+get-120917@lists.php.net to get a copy of this message
Hi everyone Since https://wiki.php.net/rfc/new_in_initializers we can store objects in global constants. However, we may not actually read or write to the properties of those objects without first fetching the constant into a local variable. const a = new stdClass; a->b = 42; // Fatal error: Cannot use temporary expression in write context $a = a; $a->b = 42; // Works fine This issue was reported twice, so it seems like this code is generally expected to work. https://github.com/php/php-src/issues/10497 https://github.com/php/php-src/issues/11781 I have created a patch here to add support for this syntax: https://github.com/php/php-src/pull/11788 Since this is a language change I would like to ask for feedback before merging. As always, if there are concerns I will create a small RFC instead. I will also only merge this for 8.4, as feature freeze for 8.3 has long passed. Ilija

« previous php.internals (#120917) next »