Declaring new elements as references while destructuring within a foreach() head
| From: | mickmackusa | Date: | Tue, 02 Jan 2024 13:35:27 +0000 |
| Subject: | Declaring new elements as references while destructuring within a foreach() head | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-122083@lists.php.net to get a copy of this message | ||
I want to ask about a quirk that I happened upon. In truth, I expected my
code to fail with a fatal error, but it turns out that while using array
destructuring in the head of a foreach() loop it is permitted to declare
new elements if the value is a reference.
Is this a bug or an intended feature?
If not a bug should a note/section clarify this behavior?
https://www.php.net/manual/en/language.types.array.php
My demonstration can be found at this evidently unhelpful question:
https://stackoverflow.com/q/77741716/2943403