Re: Unsetting the "by-reference" variable in foreach().

From: Date: Thu, 22 Dec 2016 16:52:51 +0000
Subject: Re: Unsetting the "by-reference" variable in foreach().
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-325915@lists.php.net to get a copy of this message
On 22 December 2016 at 16:23, David Harkness <david.h@highgearmedia.com> wrote: > On Thu, Dec 22, 2016 at 7:41 AM, Richard Quadling <rquadling@gmail.com> > wrote: > >> We've recently introduced PHPStan into our pipeline. One of our >> developers has started adding the initialisation of the foreach() >> referenced variable. Seemingly to appease PHPStan. >> > > I would definitely file a bug with PHPStan since it's clearly not needed, > but I understand wanting to just Get Things Done. :) > > As part of our peer-review I was just wondering why this was done as, like >> you said, unset() is very happy with what it does. >> > > If you leave it in, you may want to initialize it with null instead of an > empty array since it's going to be immediately thrown away. Seeing an empty > array makes me expect it to be filled with values in the function. > > Cheers! > David > > https://github.com/phpstan/phpstan/issues/30 Seems empty() suffers from the same issue.

« previous php.general (#325915) next »