Re: [RFC] Comparison and conversion inconsistency - need more info
| From: | Yasuo Ohgaki | Date: | Sun, 10 Nov 2013 20:22:59 +0000 |
| Subject: | Re: [RFC] Comparison and conversion inconsistency - need more info | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-70089@lists.php.net to get a copy of this message | ||
Hi all,
On Mon, Nov 11, 2013 at 4:49 AM, Yasuo Ohgaki <yohgaki@ohgaki.net> wrote:
> I really surprised by myself that I've never bitten by the
> misunderstanding more than 10 years.
> Anyway, the manual is better to explain explicitly
>
> TRUE always evaluated as 1 while
> NULL/FALSE is evaluated as 0 or least.
>
> Sorry for the confusion.
>
> Any comments?
>
I still didn't get it right :(
[yohgaki@dev ~]$ php -r "var_dump((TRUE > 100));"
bool(false)
[yohgaki@dev ~]$ php -r "var_dump((TRUE < 100));"
bool(false)
[yohgaki@dev ~]$ php -r "var_dump((TRUE > -100));"
bool(false)
[yohgaki@dev ~]$ php -r "var_dump((TRUE < -100));"
bool(false)
TRUE/FALSE only evaluated as 1/0 otherwise always return FALSE in
expression.
[yohgaki@dev ~]$ php -r "var_dump((NULL < -100));"
bool(true)
[yohgaki@dev ~]$ php -r "var_dump((NULL > -100));"
bool(false)
NULL behaves differently, though.
Because min()/max() has to use < or > results became depends on how it
compares.
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net