Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113365 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 36509 invoked from network); 4 Mar 2021 11:04:33 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 4 Mar 2021 11:04:33 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 934551804DC for ; Thu, 4 Mar 2021 02:55:17 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 4 Mar 2021 02:55:17 -0800 (PST) Received: by mail-lj1-f174.google.com with SMTP id m11so31892536lji.10 for ; Thu, 04 Mar 2021 02:55:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Bycg1PNbFzdlrZ+rT0Nlp29D9cfcrMIX/XLCjx+Gwnc=; b=PAQ6EWnlNmtX61ypN4l7U0JoIW3BwOEFHlTEIRAkunoKoEvTbdWHm117y5NdIbWl6T gw7J/gomV/j25FHWJf4Rg3VRbtVfMNLQlg7WD0ymC3724sIYjaSvO6dwwa4wwWyFInl/ W1ELZeNXzXzmtGEagRRk+2D5S23wjZeO3UicF0zzxSDCzemSi0iZqVVZyU5jmkTzahcJ D0cf/3dyoeqDJih0dm3Nkpsz7nqZMFg+xG8/fgd/Mu9cJ54DFX6BID6OdmJu1JOuIIef p1cZbx9HcTQkHwVuKczRMMiR+lZykbEcJxcRMC/2qBGuT8KdCnZfj3Sk+5oYgEz/EAGe miKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Bycg1PNbFzdlrZ+rT0Nlp29D9cfcrMIX/XLCjx+Gwnc=; b=X3FldSE0oGSd0YDSMjp9mpKiwKzA9trEzAzeTNiLEVMVElZs0wUzIfj/3PBa3K4dse kP6izk1JSiabXbhnKQejtQ+43E1lEki5wNk7mne4pGjwjUG8MN4qNmG+tpO5V2sGL4gN 7/PTMuXm9gwwp5Oo7cm3vA9IdTm3tLQf+SzuilH6+5dEpXLFgKqaas7RjsuKULpqONvK cfrQyMf38RIQ2YQBhNbVR8iIZ5QkUISAz8pKODz0vjA96bZ1N6VV+9r3fKKICdJwVCbX m1LQkzGpjFnvOBxxPqRpEmU9TfmOSVEVDtRcSDIywoV9PwsYyZpfrgBamYpGFvY3HlK1 c4pQ== X-Gm-Message-State: AOAM531+zlh6TKcjJqRn9U9MaxKlvmCEyZOuKLjsVG0Gjt2Mw9qjQoyx A4MCApdoGyLilQA5uZmoZ6ITJdqAWKab4NrYWqJ6vRyQEUa0yA== X-Google-Smtp-Source: ABdhPJzs0RSSU+bAtV0lYhbg/lc1Q1ogT2P62rxibMNuwS+zn3Pbum+68CYBe44uOrlKpDH6I841QNEmfpPmjAchRLY= X-Received: by 2002:a2e:95d2:: with SMTP id y18mr2083015ljh.353.1614855314797; Thu, 04 Mar 2021 02:55:14 -0800 (PST) MIME-Version: 1.0 References: <424A5E98-2110-4AFE-9C53-8636A6140313@benramsey.com> In-Reply-To: Date: Thu, 4 Mar 2021 11:54:58 +0100 Message-ID: To: Christian Schneider Cc: PHP internals Content-Type: multipart/alternative; boundary="00000000000066f86f05bcb3cd90" Subject: Re: [PHP-DEV] Don't compare zero exponentials in strings as equal From: nikita.ppv@gmail.com (Nikita Popov) --00000000000066f86f05bcb3cd90 Content-Type: text/plain; charset="UTF-8" On Thu, Mar 4, 2021 at 10:54 AM Christian Schneider wrote: > Am 04.03.2021 um 01:37 schrieb Ben Ramsey : > > On Mar 3, 2021, at 14:25, Kamil Tekiela wrote: > >> > >> when both are strings then chances are that this is an error. > > > > Except when comparing two values from sources known to provide numbers > as strings, such as form input and database results. :-) > > > This would be a problem for leading zeroes and leading/training spaces, > right? > > Leading zeroes theoretically could happen in databases, leading/training > spaces happen in form input and possibly databases. > Are there other 'common' cases? > The main one that comes to mind is something like '0' == '0.0'. However, the real problem is something else: Comparison behavior doesn't affect just == and !=, but also < and >. And I can see how people would want '2' < '10' to be true (numeric comparison) rather than false (lexicographical comparison). I generally agree that we should remove the special "numeric string" handling for equality comparisons, and I don't think that removing that behavior would have a major impact. But we do need to carefully consider the impact it has on relational operators. There are two ways I can see this going: 1. Decouple equality comparison from relational comparison. Don't handle numeric strings for == and !=, but do handle them for <, >, etc. The disadvantage is that comparison results may not be trichotomous, e.g. for "0" op "0.0" all of ==, < and > would return false. (To be fair, this can already happen in other cases, e.g. non-comparable objects.) 2. Don't allow relational comparison on strings. If you want to compare them lexicographically, use strcmp(), otherwise cast to number first. ("Don't allow" here could be a warning to start with.) Regards, Nikita --00000000000066f86f05bcb3cd90--