On 8/10/07, Zoltán Németh <[EMAIL PROTECTED]> wrote:
> 2007. 08. 10, péntek keltezéssel 02.31-kor Jan Reiter ezt írta:
> > Hi!
> > Thank you for your response!
> >
> > The only intention of my code was to investigate the (back then) unexpected
> > behavior of the if statement.
> >
> >
> > With $var['test'] set to "blah" this expression should be false
> > ($var['test'] == 0) for what I know ...
> >
> > $var['test'] = "blah";
> > var_dump($var['test'] == 0);
> >
> > //returns bool(true)
> >
> > Now I know why this happens! According to Table 6.5 of the Operators page in
> > the PHP Manual in this comparison all of the values are converted to
> > integer. And  atoi("blah") for sure will fail!;-) So you have to use === to
> > keep the types of the values!
>
> I found something interesting:
>
> [EMAIL PROTECTED]:~ php -r '$var = 'bla'; var_dump('0' == $var);'
> bool(true)
> [EMAIL PROTECTED]:~ php -r '$var = 'bla'; var_dump("0" == $var);'
> bool(false)
>
> version is 5.2.1
>
> is this expected behaviour to be a difference between the two types of
> quotes in this case?
>
> greets
> Zoltán Németh

I think you're little bit confused by the quotes :P
and since you don't have error reporting including E_NOTICE, you don't
see that there's some problem with your code :P
If I execute your code with the -n option, I get same results.
When I put them in a PHP file like this:
<?php
$var = 'bla'; var_dump('0' == $var);
$var = 'bla'; var_dump("0" == $var);
?>

I get :
bool(false)
bool(false)

and you probably also ;)


Tijnema
>
> >
> > Jan
> >
> >
> >
> > -----Original Message-----
> > From: Jim Lucas [mailto:[EMAIL PROTECTED]
> > Sent: Friday, August 10, 2007 1:47 AM
> > To: Jan Reiter
> > Cc: [EMAIL PROTECTED]; php-general@lists.php.net
> > Subject: Re: [PHP] I know this is not easy and I'm not stupid but...
> >
> > Jan Reiter wrote:
> > > Hi!
> > >
> > > Phil:
> > > Still I am curious what var_dump($userValues['afterDark']); at line 102.5
> > > would return.
> > > I managed to recreate that fault with
> > >
> > > $var['test'] = "blah";
> > >
> > > echo ($var['test']);
> > >
> > > if( $var['test'] == 0)
> > > {
> > >     echo "ok";
> > > }
> > >
> > > //this returns blahok -- not expected.
> > >
> > > In my case Var_dump() returns string(4) "blah" as expected.
> > >
> > > Using
> > >
> > > if( $var['test'] === 0)
> > >
> > > behaves as expected!!
> >
> > Are you wanting to only test for a empty/non-empty string?
> >
> > if so, use this.
> >
> > if ( empty($var['test']) ) {
> >       echo "var['test'] is empty";
> > }
> >
> > >
> > >
> > > Jim:
> > > TypeCasting would only be effective if you used the type sensitive
> > > comparison operator === , because with "==" 0 equals NULL equals false
> > > equals "" and so on ... or do I miss something here??
> > >
> > >
> > > Hope that solves it for you! I'm still investigating why my first examples
> > > fails. I've got the strong feeling that I'm missing something there. I
> > don't
> > > believe in a php bug or a memory leak in this case! Must be something
> > pretty
> > > obvious! Anyone a clue??
> > >
> > > Thanks,
> > > Jan
> > >
> > >
> >
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Vote for PHP Color Coding in Gmail! -> http://gpcc.tijnema.info

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to