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

From: Date: Sun, 11 Feb 2001 09:37:44 +0000
Subject: Re: PHP 4.0 Bug #9186 Updated: string compare with "==" does not work correctly
References: 1 2 3  Groups: php.dev 
Request: Send a blank email to php-dev+get-46350@lists.php.net to get a copy of this message
I accept your reasons for doing so. But actually this behaviour makes the "==" comparision to a "maybe". "Maybe they are equal." Documentation of this working will be helping not much. The users of PHP have to understand the working of "==" at the lowest level. I suggest, that you check your convert to a number. If the result is MAXINT, MININT or NaN, it would be better not converting the operands and making a string comparision. In this case you havn't to make an extra documentation on this behaviour and this operation will work like users expect. Am Freitag, 9. Februar 2001 20:31 schrieb Zak Greant: > How is this? I modified what Zeev said a wee bit: > > == is a 'loose' comparison operator [1]. > > In most cases, this is more convenient - the operator does the right thing > without needing any coaxing. In some cases, things will happen that are > confusing - particularly when comparing values that have leading zeros (0) > or when comparing very long numbers that are inside a string. > > The basic rule to follow is this: > > Character-by-character comparison is performed only if both arguments are > strings and at least one of the strings does not look like a number [2]. > > Another way to state this rule is: > > - If at least one of the arguments is not a string, a numeric comparison is > made. > > - If both arguments are strings, but both of them look like numbers, a > numeric comparison is made. > > - If both arguments are strings (and at least one of them doesn't look like > a number), a string comparison is made. > > [1] If you need to perform an exact comparison between two values, take a > look at the 'strict' comparison operator (===) and the strcmp() function. > > [2] See the manual section on types and strings to learn what rules PHP > follows for recognising numbers within strings. > > (Thanks to Zeev for clarifying this issue.) > > --zak -- Tom Anheyer G+J BerlinOnline GmbH Tel. : +49-(0)30-2327-5210 im Pressehaus am Alexanderplatz Fax: +49-(0)30-2327-5596 Karl-Liebknecht-Straße 29 E-Mail: Tom.Anheyer@BerlinOnline.de D-10178 Berlin URL: http://www.BerlinOnline.de BerlinOnline ist ein Service von Berliner Zeitung, TIP BerlinMagazin, Berliner Kurier und Berliner Abendblatt.

« previous php.dev (#46350) next »