Re: RFC proposal
| From: | Michael Morris | Date: | Fri, 02 Jun 2017 17:12:54 +0000 |
| Subject: | Re: RFC proposal | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-99326@lists.php.net to get a copy of this message | ||
What about foreach by reference, which is honestly the only time I use
referencing anymore...
foreach ($array as $key => &$value) {
$value = someOp($value);
}
Is this also bad?
On Fri, Jun 2, 2017 at 10:56 AM, Johannes Schlüter <johannes@schlueters.de>
wrote:
> On Fr, 2017-06-02 at 15:21 +0200, Bartłomiej Krukowski wrote:
> > Hello,
> >
> > PHP allows for using implicit references in arguments of function. In
> > most common case we have to mark that variable is an reference in
> > head of function, in other case we will receive fatal error (@see
> > example - http://ideone.com/7zkgQQ
> > <http://ideone.com/7zkgQQ>). There
> > is an option to use variable as implicit reference (@see example - ht
> > tp://ideone.com/T6oF7C <http://ideone.com/T6oF7C>),
> > I think it should
> > not be possible. Only explicit references should be allowed (except
> > objects).
>
> The argument to the function in the second value is an array which is
> passed by value. A copy of the array keeps the references as
> references. This is consistent. Unless we have typed arrays or anything
> like that the function call shouldn't care about the content.
>
> Aside from that references are a legacy construct and shouldn't be used
> anymore. Using objects or relying on copy-on-write usually leads to
> clearer code, reduced memory and faster execution. (in the past there
> had been a few exceptions where arrays of references were good for some
> graphs/trees with recent improvements to objects this is less the case)
>
> johannes
>
>
> http://schlueters.de/blog/archives/125-Do-not-use-PHP-references.html
>
> http://schlueters.de/blog/archives/141-References-and-foreach.html
>
> http://schlueters.de/blog/archives/180-References-Still-bad-in-PHP-7.ht
> ml
> http://schlueters.de/blog/archives/181-More-on-references.html
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>