Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:76724 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 81177 invoked from network); 20 Aug 2014 09:31:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Aug 2014 09:31:30 -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:38278] helo=mail-wg0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C5/E0-11231-1FA64F35 for ; Wed, 20 Aug 2014 05:31:29 -0400 Received: by mail-wg0-f42.google.com with SMTP id l18so7444176wgh.1 for ; Wed, 20 Aug 2014 02:31:26 -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=7LDu+IFxLt59puPIeBuGJ3Rwojjzjlk7o1byOAs/NpA=; b=xE+K5SvEiOdGMy8STlmgOwe/pjO4W7SnqgHeBNVqgMPrqHfzjWGOH8v+VK5emp5AKK WrxDlG88HU6fhGyg3iPIizhVmFcMvPLVSHurldWHcN7ffM+L/qBd+7y27i3WnJkidaq4 vmZy4QDQeSbdnTz3lerKNKgrFY5ZwI13z6b6QGQl2lfEKiqQfvOVsiZW7xh8uqaIQQXZ aZLb9U4ipHZ7WKKvgvJJ+3woSh0NQVqXwamLLxrKmYsViQIY+C+P7JVBT08fnKceECaT spwIRWhqDGGAnT5GW+i6HmVPtqgrJCmljl2DPU8wuNnCPNsXfFUR4tnIUxgikyAxMjpj dGHw== MIME-Version: 1.0 X-Received: by 10.194.186.178 with SMTP id fl18mr46949895wjc.8.1408527086325; Wed, 20 Aug 2014 02:31:26 -0700 (PDT) Received: by 10.180.95.165 with HTTP; Wed, 20 Aug 2014 02:31:26 -0700 (PDT) In-Reply-To: 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: Wed, 20 Aug 2014 17:31:26 +0800 Message-ID: To: =?UTF-8?Q?Johannes_Schl=C3=BCter?= Cc: Marc Bennewitz , Sara Golemon , PHP internals Content-Type: multipart/alternative; boundary=047d7bb04dd2a3155a05010c444c Subject: Re: [PHP-DEV] [RFC] Binary String Comparison From: tjerk.meesters@gmail.com (Tjerk Meesters) --047d7bb04dd2a3155a05010c444c Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Tue, Aug 19, 2014 at 11:07 AM, Tjerk Meesters wrote: > > On Mon, Aug 18, 2014 at 11:30 PM, Johannes Schl=C3=BCter < > johannes@schlueters.de> 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 "Wh= at'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 had mistakenly assumed that "0" =3D=3D "" would currently yield true, but= it doesn't. My apologies for that. The other two statements are still valid, though. So are these: "0" =3D=3D "0x0" "0" =3D=3D "00" > 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 th= is > 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 numb= er > cast would cause precision loss. > > >> johannes >> >> ps. yes, the example might be done nicer and better, it still represents >> a common pattern. >> >> > > > -- > -- > Tjerk > --=20 -- Tjerk --047d7bb04dd2a3155a05010c444c--