Re: Re: == and ===
| From: | Hendy Irawan | Date: | Mon, 18 Apr 2005 20:05:18 +0000 |
| Subject: | Re: Re: == and === | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-16024@lists.php.net to get a copy of this message | ||
On 4/19/05, Sara Golemon <pollita@php.net> wrote:
> > <?php echo '0' == '0.0000e0' ?>
> > 1
> >
> > <?php echo '0' == 'asadoaskd' ?>
> > (nothing, false)
> >
> > <?php echo '0' == (int)'adasd' ?>
> > 1
> >
> > That confuses me more (but understandable, and thank God PHP behave
> > this way)... I thought 'asdasd' is 0 when [implicitly] converted to
> > int [for comparison]? I guess I never knew PHP well :-(
> >
> That would be the 'Roughly Speaking' and 'not precisely how the engine
> handles it internally' parts.
>
> In the case of string to string comparison there must be at least one digit
> involved at the start of the string (or a plus/minus sign followed by
> digits, etc...) in order to qualify as a numeric string.
I don't see this is the case:
<?php echo '0' == '0asodkaowueoq' ?>
(false)
<?php echo '0' == '0 asdkasod' ?>
(false)
Isn't '0asdkoasdk' a numeric string?
However:
<?php echo 0 == 'asodkasodk' ?>
1
(this is expected, although for the $password case, it can lead to
security holes).
More niceties:
<?php echo null == 0 ?>
1
<?php echo null == '' ?>
1
<?php echo null == '0' ?>
(false)
Programming in PHP can be a lot of fun! ;-)
--
Hendy Irawan
http://www.gauldong.net
http://dev.gauldong.net