You should use strcmp()
Andi
At 11:20 AM 9/14/2001 -0700, Chris Lee wrote:
>your right === does work, I still feel that the internal auto-conversion
>should recognize that the string is to long to be an int and treat both as a
>sting. how would you force an if statement to use typecasting ?
>
>ie.
>
>if ( '12.00' == '12' )
>
>will equal as true, but maybe I want it to be compared as a string, therfore
>false.
>
>if ( (string)'12.00' == (string)'12' )
>
>doesnt work as I have found and you confirmed. ? you have to use strcmp() ?
>it would be real nice to see that built in vs a function.
>
> Chris Lee
> [EMAIL PROTECTED]
>
>
>
>----- Original Message -----
>From: "Bug Database" <[EMAIL PROTECTED]>
>To: <[EMAIL PROTECTED]>
>Sent: Friday, September 14, 2001 10:09 AM
>Subject: Bug #13304 Updated: string comparisons not working as expected
>
>
> > ID: 13304
> > Updated by: hholzgra
> > Reported By: [EMAIL PROTECTED]
> > Old Status: Open
> > Status: Closed
> > Bug Type: *General Issues
> > Operating System: linux
> > PHP Version: 4.0.6
> > New Comment:
> >
> > (string) casting won't help as it takes place *before* autoconversion
> >
> > just use strcmp() or the tripple === operator
> >
> > Previous Comments:
> > ------------------------------------------------------------------------
> >
> > [2001-09-14 12:50:18] [EMAIL PROTECTED]
> >
> > <?php
> > function check($var_1, $var_2)
> > {
> > if ( $var_1 == $var_2 )
> > echo "a true <br>\n";
> > else
> > echo "a false <br>\n";
> > if ( (string)$var_1 == (string)$var_2 )
> > echo "b true <br>\n";
> > else
> > echo "b false <br>\n";
> > if ( strcmp($var_1, $var_2) == 0 )
> > echo "c true <br>\n";
> > else
> > echo "c false <br>\n";
> > }
> >
> > check('997310325024327300', '997310325024327300');
> > check('997310325024327300', '997310325024327301');
> > ?>
> >
> > php-4.0.6
> >
> > 09:51 -root- /home/httpd/vhosts/blazers
> > php -q test.php
> > a true <br>
> > b true <br>
> > c true <br>
> > a true <br>
> > b true <br>
> > c false <br>
> > 09:51 -root- /home/httpd/vhosts/blazers
> >
> > ok I can understand the first if() failing, php is conffused and things I
>want to compare int not strings, this is a peave because php only supports
>upto signed long int, which this is much larger, I think php should realize
>this and compare them as strings.
> >
> > the second fails too .. ? this is strange because I have spec. type casted
>that as strings, they should compare fine as strings. this is where I
>beleive there is more then a quirk and more of a bug.
> >
> > the third susceeds just as it should, its just not near as elegant as a
>simple if ($var_1 == $var_2).
> >
> > --
> >
> > Chris Lee
> > [EMAIL PROTECTED]
> >
> >
> >
> > ------------------------------------------------------------------------
> >
> >
> >
> > ATTENTION! Do NOT reply to this email!
> > To reply, use the web interface found at
>http://bugs.php.net/?id=13304&edit=2
> >
>
>
>--
>PHP Development Mailing List <http://www.php.net/>
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>To contact the list administrators, e-mail: [EMAIL PROTECTED]
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]