-
Notifications
You must be signed in to change notification settings - Fork 707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initialisation of readonly properties by reference does not work (e.g. matches of preg_match) #3250
Comments
I believe this is intended behavior: you can't "modify" read-only properties through a reference. Only through direct assignment. The docs aren't really clear about this, but it is alluded to as a type of non-"plain" assignment.
That code was lifted straight from the RFC so it wasn't quite intended to be suitable for posting in the docs... |
No feedback was provided. The issue is being suspended because we assume that you are no longer experiencing the problem. If this is not the case and you are able to provide the information that was requested earlier, please do so. Thank you. |
Switching this to a doc bug because I believe the code used on that page, while fine for an RFC, needs to be cleaned up some (like with added comments) to make it more suitable for general documentation. |
Description
The following code:
https://3v4l.org/DdVMXM#v8.3.3
Resulted in this output:
But I expected this output instead:
The same-scope uninitialised readonly property is initialised by preg_match matches. Such by-reference initialisation of core method arguments works for local variables and untyped writable properties. I did not find anything in the documentation regarding readonly in combination with by-reference.
Even empty array (no matches) initialisation (which definitley would be a write-once operation) triggers the error.
Is this intended, a bug or an overlooked case?
If it actually is intended shouldn't it throw the following Error instead, however?
PHP Version
PHP 8.3
Operating System
Ubuntu 23.10
The text was updated successfully, but these errors were encountered: