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, <[email protected]> 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
>
>

Reply via email to