Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:76678 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 28688 invoked from network); 19 Aug 2014 03:08:05 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Aug 2014 03:08:05 -0000 Authentication-Results: pb1.pair.com smtp.mail=tjerk.meesters@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=tjerk.meesters@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.42 as permitted sender) X-PHP-List-Original-Sender: tjerk.meesters@gmail.com X-Host-Fingerprint: 74.125.82.42 mail-wg0-f42.google.com Received: from [74.125.82.42] ([74.125.82.42:56790] helo=mail-wg0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 14/42-14556-29FB2F35 for ; Mon, 18 Aug 2014 23:08:03 -0400 Received: by mail-wg0-f42.google.com with SMTP id l18so5646944wgh.13 for ; Mon, 18 Aug 2014 20:07:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=sko1LsshCXWAvPa7QJCZIidI9hB5pRfXspUYAN5/npQ=; b=Y/M8g65Lkc90Wl2Yt7zDFqLyQdCJSp0fC/4fF2SR7NmBeT853xeNpCIOHwi8dTackI mIUuMnwNoNNxtD3nAl+0k0JW8sr3AwXcodeZ8EpnSNDuGUg90J0vKfnsnLWLZaHRYRU+ mVg06zy/BTo1P1c2iW5O5bPcntLZIAQZWf1WD241W9ZVKVxSpfiVMXn0sJncjj7/Lu+j m+HtplQW8SgwGF9qQQEuu8pMPaX50TaYWc2ZbIz+0nL8albEqY44CzbgkRmfGTPpc/kn xrGxQ05/hAfG+/T2USN7hDtzOHP5VbxG8EoABTfoRJ4YWn8vQZ7l3UsnbcLT3fu6R8ty EkoA== MIME-Version: 1.0 X-Received: by 10.194.237.194 with SMTP id ve2mr46977071wjc.89.1408417679894; Mon, 18 Aug 2014 20:07:59 -0700 (PDT) Received: by 10.180.95.165 with HTTP; Mon, 18 Aug 2014 20:07:59 -0700 (PDT) In-Reply-To: <1408375856.2617.353.camel@guybrush> References: <53F1094B.4040100@mabe.berlin> <53F1F534.50109@mabe.berlin> <1408373244.2617.344.camel@guybrush> <37CD1B56-B84F-4586-A631-F3C7F2547FBE@gmail.com> <1408375856.2617.353.camel@guybrush> Date: Tue, 19 Aug 2014 11:07:59 +0800 Message-ID: To: =?UTF-8?Q?Johannes_Schl=C3=BCter?= Cc: Marc Bennewitz , Sara Golemon , PHP internals Content-Type: multipart/alternative; boundary=089e013d16f0816f950500f2cb23 Subject: Re: [PHP-DEV] [RFC] Binary String Comparison From: tjerk.meesters@gmail.com (Tjerk Meesters) --089e013d16f0816f950500f2cb23 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Mon, Aug 18, 2014 at 11:30 PM, Johannes Schl=C3=BCter wrote: > On Mon, 2014-08-18 at 23:09 +0800, Tjerk Meesters wrote: > > > On 18 Aug, 2014, at 10:47 pm, Johannes Schl=C3=BCter < > johannes@schlueters.de> wrote: > > > > > >> On Mon, 2014-08-18 at 14:44 +0200, Marc Bennewitz wrote: > > >> The question isn't "What's wrong with =3D=3D=3D, strcmp()?" but "Wha= t's > wrong > > >> with =3D=3D, <, >?". > > >> > > >> We have a standard way to compare two operands but currently we do > some > > >> magic things to solve something that don't need to be solved. > > > > > > Still it is a key property of the language which we can't simply > change. > > > Also mind this: All input data are strings and some databases also > > > return data as string. So code like > > > > > > if ($_GET['id'] > 0) > > > or > > > if ($db->fetchRow()[0] =3D=3D 12) > > > > > > which is common will break. > > > > Those two cases will actually not be affected, it's strictly > string<=3D>string comparisons that's being discussed here. > > Meaning that simple code you find everywhere, in every second tutorial > > foreach ($db->query("SELECT id, title FROM entries") as $row) { > echo " if ($row[0] =3D=3D $_GET['highlight_id']) { > echo " background=3D'#ff0000'"; > } > echo ">".htmlentities($row[1]).""; > } > > will suddenly fail. How wonderful! (irony) > Not necessarily and certainly not by definition; reasons for failure are less obvious such as (but not limited to): "0" =3D=3D "0.0" "11" =3D=3D " 11" (but note that "11" =3D=3D "11 " currently yields false) "0" =3D=3D "" I'm not arguing for or against this behaviour change, but I found it necessary to clear up some apparent confusion as to what repercussions this proposal carries. Another approach of attempting to solve the common issue of comparing big numbers with '=3D=3D' is to only enforce string-wise comparison if a number cast would cause precision loss. > johannes > > ps. yes, the example might be done nicer and better, it still represents > a common pattern. > > --=20 -- Tjerk --089e013d16f0816f950500f2cb23--