PHP: Not Strict Equals or Strict Not Equals

I was wondering, in PHP land, what is more performant? Strict Not Equals ( $var !== null) or Not Strict Equals ( !($var === null)), so I did some digging, in case anyone else was wondering the same.

Turns out, there is a difference, and frankly, if you have gotten this far, you have already wasted more time than computational time you’ll save knowing this, and as a result of writing this, I have wasted more time than all of you would save using this information. That said, here is the general breakdown (Note – The ERROR flag is raised because the variable is not set, expected):

For $not_null = $var !== null:

For $not_null = !($var === null):

And if this is in a conditional, you can ignore the ASSIGN, which means $var !== null is HALF the opcodes of !($var === null)! FANCY!

Now, while this is good/interesting to know, and not necessarily a bad thing to keep in mind when programming, you probably would have saved more time reading something else. Oh well.

Cheers!

Comments are closed.

Post Navigation