Re: The Context of 0
| From: | Robert Cummings | Date: | Tue, 02 Oct 2007 18:22:12 +0000 |
| Subject: | Re: The Context of 0 | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-262650@lists.php.net to get a copy of this message | ||
On Tue, 2007-10-02 at 12:14 -0500, Jay Blanchard wrote:
> [small rant]
> This morning's thread on strpos() brings up an interesting point, zero
> has a context.
>
> In certain cases 0 is the equivalent of FALSE and in other cases a 0 is
> just a 0. In the context of strpos() 0 indicates that the needle is in
> the first position of the haystack. If the needle is not found in the
> haystack a Boolean FALSE is returned. In this case 0 is not the
> equivalent of FALSE.
>
> There are other cases, most of them specific to strings, in which 0 is
> not the equivalent of FALSE. Newbies to PHP or certain functions will no
> doubt encounter these cases at some point.
>
> Exercise care when using 0 to determine if something is FALSE and
> understand that 0 has context.
> [/small rant]
I don't know why this is a rant. In most languages 0 is equivalent to
false. Even in C when you:
#define FALSE 0
If you want to match false exactly then use the tools provided. Namely
the equality operator === and not the equivalence operator ==.
Cheers,
Rob.
--
...........................................................
SwarmBuy.com - http://www.swarmbuy.com
Leveraging the buying power of the masses!
...........................................................