doubledee Posted February 7, 2012 Share Posted February 7, 2012 I want to negate this line of code... if (is_null($activationCode)){ Is this the proper way to do it... if (!is_null($activationCode)){ Thanks, Debbie Quote Link to comment https://forums.phpfreaks.com/topic/256586-negating-isnull/ Share on other sites More sharing options...
ttocskcaj Posted February 7, 2012 Share Posted February 7, 2012 Yes. That is correct. Why not just try it? if (!is_null($activationCode)){ echo "Not Null"; } else echo "Null"; Quote Link to comment https://forums.phpfreaks.com/topic/256586-negating-isnull/#findComment-1315372 Share on other sites More sharing options...
darkfreaks Posted February 7, 2012 Share Posted February 7, 2012 !=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. Quote Link to comment https://forums.phpfreaks.com/topic/256586-negating-isnull/#findComment-1315373 Share on other sites More sharing options...
scootstah Posted February 7, 2012 Share Posted February 7, 2012 !=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. Quote Link to comment https://forums.phpfreaks.com/topic/256586-negating-isnull/#findComment-1315494 Share on other sites More sharing options...
doubledee Posted February 7, 2012 Author Share Posted February 7, 2012 Okay, thanks everyone! Debbie Quote Link to comment https://forums.phpfreaks.com/topic/256586-negating-isnull/#findComment-1315602 Share on other sites More sharing options...
gizmola Posted February 10, 2012 Share Posted February 10, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/256586-negating-isnull/#findComment-1316434 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.