RE: [PHP] Inconsistent String Definition (string position starts at zero)?
| From: | Ignacio Vazquez-Abrams | Date: | Sun, 26 Nov 2000 03:40:32 +0000 |
| Subject: | RE: [PHP] Inconsistent String Definition (string position starts at zero)? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-27219@lists.php.net to get a copy of this message | ||
On Sun, 26 Nov 2000, Adam Warner wrote:
> Thanks Ignacio,
>
> !==false worked! I thought the extra = was a typo. I really appreciated the
> very useful and prompt response. I've still got to try and understand why
> that worked. The manual states:
>
> One last thing worth mentioning is the truth value of expressions. In many
> events, mainly in conditional
> execution and loops, you're not interested in the specific value of the
> expression, but only care about
> whether it means TRUE or FALSE (PHP doesn't have a dedicated boolean type).
The PHP manual is lying about there not being a Boolean type in PHP 4. True
and false exist just as much as 4 or "Hello, world!" or Array(1 => "one", 2
=>
"three"). It just so happens that 0, "", and Array() evaluate to false in a
conditional.
> The truth value of
> expressions in PHP is calculated in a similar way to perl. Any numeric
> non-zero numeric value is TRUE,
> zero is FALSE. Be sure to note that negative values are non-zero and are
> thus considered TRUE! The
> empty string and the string "0" are FALSE; all other strings are TRUE. With
> non-scalar values (arrays
> and objects) - if the value contains no elements it's considered FALSE,
> otherwise it's considered TRUE.
>
> --
>
> OK so there does appear to be a manual omission. But what's the significance
> of the extra symbol because !=false doesn't work?
>
> I'll give it a go:
> !=false evaluates whether the expression is not zero.
Or "". False is funny in that it evaluates to either depending on the context.
> !==false evaluates whether the function returns false.
>
> So why doesn't ===true evaluate whether the function returns not false?
strpos() never returns true. It only returns 0, a positive integer, or
false.
>
> Thanks again,
> Adam
>
--
Ignacio Vazquez-Abrams <ignacio@openservices.net>