Question

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?

Was it helpful?

Solution

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.

Hope that answers your question.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top