Jump to content

Negating isNull()


doubledee

Recommended Posts

!=null

!==null

!is_null()

 

all do the same thing. however issetwill sometimes return true even if null. however something i read somewhere said doing !is_null(var) is 10 times slower than using !=null or !==null.

 

Based on the benchmark I just ran, == null was like .4 microseconds faster than is_null(). I'm assuming the reason is because is_null() is an extra function call. Either way, it's a negligible difference.

Link to comment
https://forums.phpfreaks.com/topic/256586-negating-isnull/#findComment-1315494
Share on other sites

Debbie,

  I believe this is the 2nd of these threads that I've seen where you are asking what the ! operator does.  I'd encourage you to put some time into understanding logical operators so that you don't have to repeat these types of questions. 

 

I would also encourage you not to use functions when a simple comparison will do.  Functions always have some overhead, and with php language built-ins like isset() will always be preferrable to other ways of doing things from a performance standpoint. 

 

In this case:

 

if (!(is_null($activationCode)) {
//...
}

 

Can be written either as:

 

if ($activation != null) {

}

 

or depending, on the nature of how $activation is getting its value:

 

if ($activation !== null) {

}

 

In short, try not to use the not operator, not to mention the is_null() function when you don't have to, and this is a case where you clearly don't.

Link to comment
https://forums.phpfreaks.com/topic/256586-negating-isnull/#findComment-1316434
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.