[drupal-devel] What the difference between '==' and '==='

Scott Courtney scott at 4th.com
Wed Mar 30 13:50:53 UTC 2005


On Wednesday 30 March 2005 08:11, Carl McDade wrote:
> Hmm,
> 
> After I wrote that last post I realized that booleans may be effected
> also. You might check this:
> 
> 0 == FALSE; //true
> 0 === FALSE; //false

Which is one of the main reasons for the existence of "===". Some functions,
such as some of the string searches, can return zero as a real data value if
they happen to match on the first character of a string, but they also return
FALSE if they don't match at all. "===" provides the calling routine a way to
distinguish between 0 and FALSE.

It can also be used to distinguish, with some of the more complex data types
such as strings, whether two reference variables are for the *same* item or
for two *different* items that have the identical contents.

Scott

-- 
-----------------------+------------------------------------------------------
Scott Courtney         | "I don't mind Microsoft making money. I mind them
scott at 4th.com          | having a bad operating system."    -- Linus Torvalds
http://4th.com/        | ("The Rebel Code," NY Times, 21 February 1999)
                       | PGP Public Key at http://4th.com/keys/scott.pubkey



More information about the drupal-devel mailing list