RE: [PHP-DEV] Comparison: ('*' == 0) ... True or false
| From: | Scott McNaught [Synergy 8] | Date: | Tue, 11 Mar 2008 10:44:50 +0000 |
| Subject: | RE: [PHP-DEV] Comparison: ('*' == 0) ... True or false | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-36096@lists.php.net to get a copy of this message | ||
"If you compare an integer with a string, the string is converted to a
number. If you compare two numerical strings, they are compared as
integers." Well... I just feel stupid now :)
I am writing something which is extracting parts of a crontab. The variable
contained "*" was being compared to 0.
This would have clicked for me had it been anything else, but because it was
"*" my thoughts were that there was some new wild-card thing going on that I
hadn't heard about.
Cheers guys and sorry for my dumb post!
Scott
-----Original Message-----
From: Pierre Joye [mailto:pierre.php@gmail.com]
Sent: Tuesday, March 11, 2008 8:25 PM
To: Scott McNaught [Synergy 8]
Cc: internals@lists.php.net
Subject: Re: [PHP-DEV] Comparison: ('*' == 0) ... True or false
On Tue, Mar 11, 2008 at 11:17 AM, Scott McNaught [Synergy 8]
<scott.mcnaught@synergy8.com> wrote:
> Hey guys,
>
> I don't know whether to post this as a bug or not. But I was tricked
when programming today.
>
> It seems that the character "*" is non-strictly equivalent to 0. Is this
the correct behavior or am I missing something?
>
> Test case:
>
> <?php
>
> var_dump('*' == 0);
>
> ?>
>
> Shows boolean(true).
>
> I was unable to find any documentation as to why this would be the case.
http://www.php.net/manual/en/language.operators.comparison.php
--
Pierre
http://blog.thepimp.net | http://www.libgd.org
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php