Re: Only variables can be passed by reference
| From: | Andrea Faulds | Date: | Thu, 04 Dec 2014 23:18:50 +0000 |
| Subject: | Re: Only variables can be passed by reference | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-79433@lists.php.net to get a copy of this message | ||
> On 4 Dec 2014, at 19:58, Kalle Sommer Nielsen <kalle@php.net> wrote:
>
> I think we should solve these on a case-by-case basis, I can think of
> one reason why the warning exists, and that is because it modifies the
> array pointer and the argument is sent by reference. But I think we
> can safely remove the warning if the parameter was not sent by
> reference, as then we would expect the user to use the return value of
> array_pop() to assign the value from. I don't think we should remove
> warnings if you pass a statically value to it, sure some APIs can
> return a variable length/dynamic array but then I think they should be
> referenced into a variable and then passed to the function as they are
> most likely going to be used later, I can't really think of a case
> where it would be useful to send a return value of some API call to
> array_multisort() and then use the boolean true or false to check if
> it was a successful call for example..
Doing it case-by-case seems like the most pragmatic approach.
That being said, I’m not sure there are many cases, if any, for which I don’t think a warning
should be shown. It feels like an abuse of the internal array pointer functions
(next/prev/key/extract/etc.) to use them like this. It’d probably be better to add non-by-ref
functions that do the same thing instead.
--
Andrea Faulds
http://ajf.me/