Page MenuHomePhabricator

Forbid empty() on set variables
Closed, ResolvedPublic

Description

empty is as widely used as dangerous. Per the php.net manual and our coding conventions, empty should only be used when the target may be unset, to suppress errors. Otherwise, a simple boolean cast is enough.

Given how hard is to determine whether a variable is set, this should be implemented within phan. I opened an upstream task for it, https://github.com/phan/phan/issues/3167. If an upstream rule is added, we must make sure to enable it in our config.

Event Timeline

Change 929382 had a related patch set uploaded (by Daimona Eaytoy; author: Daimona Eaytoy):

[mediawiki/tools/phan@master] Add plugin to forbid `empty()` on defined variables and properties

https://gerrit.wikimedia.org/r/929382

I implemented a custom plugin instead, because it seemed easier. It can still be moved to upstream in the future if it's wanted.

Change 929382 merged by jenkins-bot:

[mediawiki/tools/phan@master] Add plugin to forbid `empty()` on defined variables and properties

https://gerrit.wikimedia.org/r/929382

Will be in the next mediawiki-phan release.