Re: [RFC] Readonly Variables
| From: | Tim Düsterhus | Date: | Tue, 24 Feb 2026 11:35:58 +0000 |
| Subject: | Re: [RFC] Readonly Variables | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-130153@lists.php.net to get a copy of this message | ||
Hi
Am 2026-02-24 01:45, schrieb Ben Ramsey:
Objects are references, whether or not using the & operator.
This is false. Quoting from the PHP documentation at https://www.php.net/manual/en/language.oop5.references.php:
One of the key-points of PHP OOP that is often mentioned is that "objects are passed by references by default". This is not completely true. […] In PHP, an object variable […] contains an object identifier which allows object accessors to find the actual object.-
Is the idea to allow objects (and arrays) similar to how JavaScript handles these with const? That is, the objects and arrays themselves are mutable, but the variable name cannot be reassigned to a new object or array?
The proposed semantics in the RFC are very clearly modeled after the existing behavior of readonly properties in PHP: Immutability of identity, which would be “cannot be reassigned”. I'd like to note here that arrays in PHP are values, thus they are immutable when stored in a readonly property (see https://3v4l.org/vS0ij). I expect the same from this RFC, but having array-semantics spelled out explicitly + an example certainly makes sense for clarity.
Best regards
Tim Düsterhus