Re: [RFC] Saner string to number comparisons

From: Date: Thu, 16 Jul 2020 07:51:23 +0000
Subject: Re: [RFC] Saner string to number comparisons
References: 1 2 3 4 5 6 7 8 9 10 11 12  Groups: php.internals 
Request: Send a blank email to internals+get-111036@lists.php.net to get a copy of this message
On Wed, Jul 15, 2020 at 5:12 PM Arnold Daniels <arnold.adaniels.nl@gmail.com> wrote: > Hi Nikita, > > One of the problems with numeric string comparisons is that it might > interpret a hexadecimal value as scientific notation > > $red = '990000'; > $purple = '9900e2'; > $red == $purple; // true > > I suggest only interpreting a number formatted with a sign ("1e+100") or > with decimals ("1.0e100") as scientific notation as part of this RFC. These > are the notations that languages use when casting a float to a string, > never "1e100" > > PHP "1.0E+100" > JavaScript "1e+100" > Python "1e+100" > Ruby "1.0e+100" > Java "1.0E100" > > Arnold > Hey Arnold, I don't want to include this change in this RFC (because the proposal does not otherwise touch string-to-string comparison at all), but I do think this is a very good idea. I was not aware of this particular variant of the issue (i.e., that it also occurs with prefixes other than "0e") and this seems like a pragmatic way to resolve that particular ambiguity. A question here would be whether to make this something specific to string-to-string comparisons, or make a general change to numeric string recognition (i.e., no longer treat "1e100" as a numeric string, only "1.0e100" or "1e+100".) Regards, Nikita

« previous php.internals (#111036) next »