Re: Assigning to a reference returned by a function/method
| From: | Marco Pivetta | Date: | Fri, 31 Aug 2018 18:56:46 +0000 |
| Subject: | Re: Assigning to a reference returned by a function/method | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-103109@lists.php.net to get a copy of this message | ||
I'd rather put everything that has to do with references in a pot and throw
it at the core of the sun 🔥
Expanding features around references, especially since they are known to be
problematic, makes them a bigger problem.
On Fri, 31 Aug 2018, 20:44 Claude Pache, <claude.pache@gmail.com> wrote:
> Hi internals,
>
>
> Today I tried something like that:
>
> <?php
> function &fooRef(...$args) {
> // ... impl details
> return $someRef;
> }
>
> fooRef('a', 'b') = 42;
> ?>
>
> and it failed miserably (Fatal Error: Can't use function return value in
> write context).
>
> Naturally, as workaround, I could write:
>
> <?php
> $ref =& fooRef('a', 'b');
> $ref = 42;
> unset($ref);
> ?>
>
> which is passable for one instruction, but not so much for ten similar
> instructions in a row.
>
> Another hackier workaround:
>
> <?php
> function arrayFoo(...$args) {
> // ... impl details
> $arr = [ &$someRef ];
> return $arr;
> }
>
> arrayFoo('a', 'b')[0] = 42;
> ?>
>
> (... and I was wondering that it worked, while <?php [ &fooRef('a',
> 'b')
> ][0] = 42; ?> triggered a fatal error).
>
>
> So... what do you think? Is it reasonable to allow to assign to a
> function/method return value, when it is a reference?
>
>
> —Claude
>
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>