When to use === ,! == over ==,! = In PHP

Possible duplicate:
php == vs === operator

I understand the difference between ===, !==vs. ==, !=In PHP, but I always think that I prefer ===and !==, but I have no real reason. The PHP.net documentation often says “warnings” about what you should use ===to check the return value for some built-in functions. So my question is why should I use one set of statements over another?

Many thanks:).

+3
source share
4 answers

, , ( , ) ( , ).

, .

+5

=== !== , , .

== != - - , php

+3

, / false . 0 - , false , ===, . , === , , , null , false. , / PHP, , , . == - , , .

+3

===and !==important if you use a function that can return 0 as successful, and FALSE when it fails. In PHP 0, it is also FALSE, which would lead to the conclusion that the function failed.

if(somefunction() == 0) {
    // Do something
}

Assuming some function returns 0 when the function was successful, and FALSE when it failed, the snippet above will run when the return code is FALSE.

Use ===prevents this, because it will only work if the answer is really 0.

+1
source

All Articles