Re: Re: Strange comparison behaviour

From: Date: Fri, 13 May 2005 15:11:40 +0000
Subject: Re: Re: Strange comparison behaviour
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-215145@lists.php.net to get a copy of this message
On Fri, 2005-05-13 at 06:34, Erwin Kerk wrote: > Bogdan Stancescu wrote: > > You probably mis-typed something: > > > > [bogdan@myserver ~]$ php > > <? > > if ("info" == 0) echo "is 0\n"; else echo "not 0\n"; > > ?> > > Content-type: text/html > > X-Powered-By: PHP/4.3.11 > > > > is 0 > Tried that, but notice the PHP Version, it is failing in PHP 4.1.2! > > Erwin Kerk Same behavior on 5.x - I suspect something to do with the 'type' and loose comparison operators. According to table 2: http://us4.php.net/manual/en/types.comparisons.php is should evaluate as true. Looking at the ordinal values revealed nothing to me... <?php $string = "info"; $len = strlen($string); $lst = $string{strlen($string - 1)}; echo '<pre>'; echo ($string == 0) ? "is 0\n" : "not 0\n"; echo (rtrim($string, $lst) == 0) ? "is 0\n" : "not 0\n"; echo "-----------------------\n"; for($i=0; $i<$len; $i++) { $ord_value = ord($string[$i]); echo chr($ord_value) . "=" . $ord_value . "\n"; } echo '</pre>'; ?> Anyway, I suspect using ($string === 0) will give you the expected results. -- s/:-[(/]/:-)/g Brian GnuPG -> KeyID: 0x04A4F0DC | Key Server: pgp.mit.edu ====================================================================== gpg --keyserver pgp.mit.edu --recv-keys 04A4F0DC Key Info: http://gfx-design.com/keys Linux Registered User #339825 at http://counter.li.org

« previous php.general (#215145) next »