Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why should is_null() not be used?

Running CodeSniffer PHP style tests gave me the following error:

The use of function is_null() is forbidden    
Squiz.PHP.ForbiddenFunctions.Found

Why would use of is_null() be forbidden?

like image 568
8128 Avatar asked Sep 21 '12 08:09

8128


1 Answers

We implemented this rule in the Squiz standard for consistency.

Another part of the standard forbids implied expressions, for example if ($var) {.... So you need to write if ($var === TRUE) {....

Due to this, a comparison of a NULL value would look like this:

if (is_null($var) === TRUE) {
}

Given the fact you already have to write the second half of the comparison, it is easier to just write:

if ($var === NULL) {
}

The code is simpler this way, but also (and more importantly) more consistent with the way we do things.

That's the only reason. We weren't concerned about performance and didn't have any issues with the is_null() function itself. It works fine as far as I know.

like image 104
Greg Sherwood Avatar answered Oct 13 '22 16:10

Greg Sherwood