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

[email protected] (Richard Quadling)
Newsgroups php.general
Message-ID <CAKUjMCUazQ+vAHtGE--66MGzABANdmEaOcsNwMke45B9xxypXg@mail.gmail.com>
On 22 December 2016 at 16:23, David Harkness <[email protected]>
wrote:

> 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
>
>
https://github.com/phpstan/phpstan/issues/30

Seems empty() suffers from the same issue.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.