Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a rule for enforcing strict comparison (===) using PHP Code Sniffer?

As title says. I am looking for a rule similar to eslint's eqeqeq, but for PHP. I would want to enforce the use of ===/!== instead of ==/!=.

I have tried googling and searched through their repo as well, but unfortunately to no avail. Just wanna ask here if someone knows of a rule that I have missed before I open an issue on Github :)

like image 826
carestad Avatar asked Dec 28 '25 04:12

carestad


1 Answers

Try including the Squiz.Operators.ComparisonOperatorUsage sniff. It enforces strict type comparisons, including banning the use of !$foo in favour of === false.

It also bans implicit true comparisons, so you can't do something like if ($foo), but you can disable that by excluding the Squiz.Operators.ComparisonOperatorUsage.ImplicitTrue error code if that it too strict for your standard.

like image 62
Greg Sherwood Avatar answered Dec 30 '25 18:12

Greg Sherwood



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!