Re: PHP 4.0 Bug #9186 Updated: string compare with "==" does not work correctly

From: Date: Fri, 09 Feb 2001 16:10:24 +0000
Subject: Re: PHP 4.0 Bug #9186 Updated: string compare with "==" does not work correctly
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-46090@lists.php.net to get a copy of this message
As much as I hate to be wrong, I have to say that you are correct. --zak ----- Original Message ----- From: <tom.anheyer@berlinonline.de> To: <php-dev@lists.php.net> Sent: Friday, February 09, 2001 8:59 AM Subject: [PHP-DEV] PHP 4.0 Bug #9186 Updated: string compare with "==" does not work correctly > ID: 9186 > User Update by: tom.anheyer@berlinonline.de > Status: Bogus > Bug Type: Scripting Engine problem > Description: string compare with "==" does not work correctly > > I think there is no reason to convert any type if both > operands of the comparision are of the same type. It costs > time and it's completely not necessary. This is a bug. > > I can not see any description of this behavior in the > manual. The string type section descibes only what is > happen if a string is converted. > > > > Previous Comments: > -------------------------------------------------------------------------- - > > [2001-02-09 10:27:46] zak@php.net > Actually, this is a feature - it is described in the manual. Strings that look like numbers are converted to numbers. Large numbers - like the ones below may not convert perfectly from a string to a number. Review the manual section on PHP types in general and strings in particular (http://uk.php.net/manual/en/language.types.string.php) > > While this is a relatively subtle bug, you can ensure that you are dealing with strings by quoting the variables being compared or by using the === operator. This behavior is exploited quite often in PHP scripts. However, perhaps it would be nice if PHP generated an notice level error when it occured so that users have some recourse when it happens unexpectedly. > > If you feel strongly about this, propose it to the developers as a feature request. Post your request on the php-dev@lists.php.net list (sub at php-dev-subscribe@lists.php.net) - if you get no response, be polite but persistant. :) > > -------------------------------------------------------------------------- - > > [2001-02-09 03:25:24] tom.anheyer@berlinonline.de > First the test script: > > <? > $a = '012345678901234567'; > $b = '012345678901234568'; > echo ($a == $b) ? "a equal bn" : "a not equal bn"; > echo ($a === $b) ? "a equal bn" : "a not equal bn"; > printf ("as string: a=%s b=%sn", $a, $b); > printf ("as float: a=%.0f b=%.0fn", $a, $b); > printf ("as int: a=%d b=%dn", $a, $b); > ?> > > and its output: > > a equal b > a not equal b > as string: a=012345678901234567 b=012345678901234568 > as float: a=12345678901234567 b=12345678901234567 > as int: a=2147483647 b=2147483647 > > Zend trys to convert the arguments to numbers if both > arguments are strings. This is not good and its not a > feature. > > > > > > -------------------------------------------------------------------------- - > > > Full Bug description available at: http://bugs.php.net/?id=9186 > > > -- > PHP Development Mailing List <http://www.php.net/> > To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net > For additional commands, e-mail: php-dev-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > >

« previous php.dev (#46090) next »