Re: Draft RFC: foreach iteration of keys without values
| From: | Nikita Popov | Date: | Thu, 03 Sep 2020 08:25:01 +0000 |
| Subject: | Re: Draft RFC: foreach iteration of keys without values | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-111806@lists.php.net to get a copy of this message | ||
On Thu, Sep 3, 2020 at 10:19 AM Dik Takken <dik.takken@gmail.com> wrote:
> On 03-09-2020 09:38, Brent Roose wrote:
> > Hi all
> >
> > I want to point out the use-case when you're using CS tools, static
> analysers and IDEs: they report unused variables as errors. There are ways
> around those errors, but it's more convenient if there's language support.
> I'd say that conceptually it's also more correct: if you're not using a
> variable, it shouldn't be there.
>
> Exactly this.
>
> The intent of a particular language construct does not only need to be
> clear to human readers but also to machines. More explicit intent leads
> to stronger static code analysis tools, which helps us catch more bugs
> earlier.
>
> Regards,
> Dik Takken
>
Static analysis tools don't need a language feature to support this. They
can recognize the $_ pattern and not emit an unused variable warning for
it. I'd suggest submitting a feature request.
Nikita