Re: [PHP] Unsetting the "by-reference" variable in foreach().
[email protected] (David Harkness)
| Newsgroups | php.general |
|---|---|
| Message-ID | <CA+MN=jAc6oWspLFJQdatfEoaNwHp9e2v8hWCJk=hqPnr36z7zQ@mail.gmail.com> |
On Thu, Dec 22, 2016 at 7:41 AM, Richard Quadling <[email protected]> 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