Re: PHP 4.0 Bug #9186 Updated: string compare with "==" does not work correctly
| From: | Zak Greant | Date: | Fri, 09 Feb 2001 17:32:02 +0000 |
| Subject: | Re: PHP 4.0 Bug #9186 Updated: string compare with "==" does not work correctly | ||
| References: | 1 2 3 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-46092@lists.php.net to get a copy of this message | ||
Alan van den Bosch wrote:
[snip]
> This issue arises from the loose typing in PHP with the introduction of
> first class boolean type (the true and false keywords), from my
> understanding the sematics being applied here are as follows (poetic
license
> applied liberally);
>
> == is (has become?) a boolean logic operator, dealing in terms of 'true'
> and 'false' values, so its terms are type cast to either 'true' or
'false'.
> When applied to strings, a 'false' string is zero length or contains '0',
> all other strings are 'true'.
> [please dont ask 'what if the string is NULL... ;-)]
>
> If you dont want your terms to be treated as (type cast to) boolean values
> use the strict equallity operator ===
>
> > > I can not see any description of this behavior in the
> > > manual. The string type section descibes only what is
> > > happen if a string is converted.
>
> The manual doesnt seem very clear on this at all, but == behaves something
> like ^(A xor B)
While I certainly appreciate the support :) - I am not sure that this is a
correct appraisal of the situation. We should take a look at the source
code and see what it actually does. My impression is that it should cast
the values as strings and then compare the strings.
--zak