Re: Unsetting the "by-reference" variable in foreach().
| From: | David Harkness | Date: | Thu, 22 Dec 2016 16:23:23 +0000 |
| Subject: | Re: Unsetting the "by-reference" variable in foreach(). | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-325914@lists.php.net to get a copy of this message | ||
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