Search code examples
phpcomparison-operators

The usage of == and === in php


Possible Duplicate:
What does “===” mean?

I am confused with the use of those operators in php, I am not quite sure when should I use === and when ==.

for example why/when should I write:

if( $some_method_that_returns_something_or_false() === FALSE) {
      //do stuff
}

and when with ==?

Also, does === means I must return bool FALSE or I can return 0? When it is considered an bad practice to use === or ==?

Also when putting something like this:

 if($some_method_that_returns_true_or_false()) {

 }

is that $some_method_that_returns_true_or_false() == TRUE or some_method_that_returns_true_or_false() === TRUE?


Solution

  • === means exact value, so for true it has to be true, while == checks for the meaning of the value, so true will be also a value of '1' or a whatever String.