Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113366 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 38781 invoked from network); 4 Mar 2021 11:23:33 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 4 Mar 2021 11:23:33 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9FE1D1804C0 for ; Thu, 4 Mar 2021 03:14: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-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) (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 03:14:16 -0800 (PST) Received: by mail-lj1-f179.google.com with SMTP id u4so32823002ljh.6 for ; Thu, 04 Mar 2021 03:14:16 -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=FZOg2NA80l6yAlJ7nQljw3iBNww2hE7cgp7UiiKJzS8=; b=cTYSju1j90+yf5b89GdAgFQbc8lUJZZws32xS0YqygNa2RjEHJGZj+cSJxaw+VlkRI /JXj6HF2MOE7kY3atokXCD5vCKZv6hGl8K6rw98h0ePZo5IjIng/uBZ7VuHV4hLAylLv Dy3udS/Ky+3A33FnRyhs2LZaS87ssU/PKamevyIIXIKOF7wwem+tn145q6oiyih6mm2i 9aCQJczmZbJO6HnuJh18m0mWYAAPQS1fOfGW6/q07dYyPmWQw3OhGN5SP4Hb4Ybrqb8v 4Eg4mZF+OdHJ+HQnoW9NE80HG6yFpitpd6dN0DklsAI43mhv7/SiSyQJXqSKhtf+vJ9y E2fQ== 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=FZOg2NA80l6yAlJ7nQljw3iBNww2hE7cgp7UiiKJzS8=; b=hvieh/UIHpm9VGaQO6nQvX2aEAiVhnVU6pKytxLWIWaQ0YskMpsI6R6MVKKRoMa8j2 QAXrLnLoQzKdv7VGAo0Q4eOJlVJWCBSySTAbwq5a8KEpF96nL+smlld1r8uDzOd86MM2 Gj814R36x/sJRFaXH0gzJIr+q7HfSGFb/+R3S5SZfV/r+lILI8XvkKrmB8GyaVPGl3Hq MTqCuR5QusxA3P6GYNDfVxrQZJg6RA/gQDdrA/w/cW1jP6rVCdjrX/8OBn1j5Fl8GzWB 0JI4+VxZMqeAjjL7DHHFCve8QrW318Z0haIcHBUvC/u6eTdVoFYC3ykpuI4CtAVtIxST SrvA== X-Gm-Message-State: AOAM5334o4W4s+4YEMGjWPWkqyEKvr6vDBw/fbBy3IUh8GJbElL8gCRd 4rKvQOeizyQpRpw0DTClWJIacW5MKjFebrv6F98= X-Google-Smtp-Source: ABdhPJwBg49Yy7bynuvuQ46ciHRpOi8mSb2MXAf5wBVtQAjEdlY37xeNTnWtHDUM62GK6yk8pvhO5JWG0SE1SUlsJDw= X-Received: by 2002:a2e:8503:: with SMTP id j3mr2029412lji.272.1614856453189; Thu, 04 Mar 2021 03:14:13 -0800 (PST) MIME-Version: 1.0 References: <424A5E98-2110-4AFE-9C53-8636A6140313@benramsey.com> In-Reply-To: Date: Thu, 4 Mar 2021 12:13:57 +0100 Message-ID: To: Christian Schneider Cc: PHP internals Content-Type: multipart/alternative; boundary="00000000000041730405bcb41117" Subject: Re: [PHP-DEV] Don't compare zero exponentials in strings as equal From: nikita.ppv@gmail.com (Nikita Popov) --00000000000041730405bcb41117 Content-Type: text/plain; charset="UTF-8" On Thu, Mar 4, 2021 at 11:54 AM Nikita Popov wrote: > 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.) > Regarding the last point, while I think that lexicographical comparison with explicit < and > operators is pretty uncommon, sorting an array of strings and expecting lexicographical order probably isn't unusual. While SORT_STRING can be passed to enforce that, people probably expect that as the default behavior. So just not allowing relational comparison is not a great option either. Nikita --00000000000041730405bcb41117--