Re: comparison efficieny
| From: | Burhan Khalid | Date: | Thu, 13 Nov 2003 11:41:02 +0000 |
| Subject: | Re: comparison efficieny | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-169470@lists.php.net to get a copy of this message | ||
Jon Hill wrote:
I am sure I read somewhere that doing the following if (false === $variable) was a better option than if ($variable === false) maybe it was a dream or is there something in this?=== is type-safe comparison (iirc) == is not type-safe = is assignment (obviously) if ($variable = "foo") will always be true (you are assigning a value to a variable, and unless by some cosmic occurance it cannot assign a variable, that will be the only time that would return false). if ($variable == "foo") will compare the value of $variable and return true of its "foo" if ("foo" = $variable) this will generate an error because you are trying to assign a value to a literal (string). It helps catch the "== where = should be" type errors. if ("foo" == $variable) this will comapre the value of $variable and return true of its "foo" if ($variable === "foo") this will return true only if $variable is a string "foo" (iirc). Hopefully this helps, -- Burhan Khalid phplist[at]meidomus[dot]com http://www.meidomus.com ----------------------- "Documentation is like sex: when it is good, it is very, very good; and when it is bad, it is better than nothing."