Don't compare zero exponentials in strings as equal

From: Date: Wed, 03 Mar 2021 14:04:15 +0000
Subject: Don't compare zero exponentials in strings as equal
Groups: php.internals 
Request: Send a blank email to internals+get-113346@lists.php.net to get a copy of this message
Hi internals,

PHP's == comparison semantics for strings have a peculiar edge-case, where
comparisons of the form "0e123" == "0e456" return true, because they are
interpreted as floating point zero numbers. This is problematic, because
strings of that form are usually not numbers, but hex-encoded hashes or
similar.

I'm wondering if it may make sense to special-case the comparison semantics
to not consider strings of the form "0e[DIGITS]" equal, unless they are
exactly equal (i.e., fall back to lexicographical if both sides of the
comparison are zero exponentials).

Here's a possible implementation: https://github.com/php/php-src/pull/6749

Of course, the usual rule that you should always use === still holds, but
this at least eliminates the most dangerous edge case.

Regards,
Nikita


Thread (16 messages)

« previous php.internals (#113346) next »