Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:106070 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 49343 invoked from network); 26 Jun 2019 13:22:49 -0000 Received: from unknown (HELO mail-ed1-f48.google.com) (209.85.208.48) by pb1.pair.com with SMTP; 26 Jun 2019 13:22:49 -0000 Received: by mail-ed1-f48.google.com with SMTP id k8so2614923eds.7 for ; Wed, 26 Jun 2019 03:39:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=2RknkryySexUq/PtJUw1DQskwNUz8yJsGFvy5PzXC38=; b=GahdD7+faOTCq5saQAndy6pau1BUY181XxM5ZTKrxL2A9yvd4zHLXa3GAFUE3zuU4f TjqDxQGxlGGay3vQwdDO+oxuOoDb1HSrcUIQRIjZ+7mlgB5iA/YxFgv0l4bo/YGnJtSM CD1oA9osuQcVbXCl3ukdhnVRx/Yn7uISIxWKRGOMzj8zT7BBfyUQNWnevVeGOTgLTZAz zeQqCuJZB2RTBLe5Yk0OZqJOArxfnK2bHk2Rjz2R2mXDzUMeLPOxVugeBkMkiW05ukTc bx0/amOggc9IX8K1TBI86mdpO69PBSSBR2V1S2gxS6tDc6G/0QsZog8VqnfEt+YIt3Mp fZiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=2RknkryySexUq/PtJUw1DQskwNUz8yJsGFvy5PzXC38=; b=YY6wVqV4O3gMulXQdwqIxtVl4a3nugf+f6BmfVQxy7TliSaUF3IEnptf3Ri+q1l2Ii vWZEmAH+IW1Z1Y6D5gy4Qdljuv3Z3pRPxGfuHB1Yu19TehfXReInVvJPC9ML3HNBVXHP jXrVSq47SkXpbDD1C9ELKed+5OWykgo0I9ILJeYpEhNsgEO4aLSjlLjVaPTZe5ZmPu3b 2XOnEtsPY3N0PzHuLb4zA0fxMpI/XPteQNyLXrZSBBBccvTfbeqHYUkUBfPh8a7fOJMB w3TtrBe0KKn0X+UuVNkZ1oZLO4ZJ/jvuxUp+E7PuLSVqOMQcSpvr3rEpR2yxV6zkz/fB yI+A== X-Gm-Message-State: APjAAAXW6ARHIcAumFjWEA47GfBsLNWCpuyyf46fnUqlaZfHsHHoJQel sy4c6nslYKr+XlLmg9LtqH7SSDo4uUk= X-Google-Smtp-Source: APXvYqzUIvS0hQgOz3f6t3QeUUUwiBMbl6kAkMDAiR+80DD0SdQil2ePEihAjNsshL4mMjXFPJAQsA== X-Received: by 2002:a17:906:244c:: with SMTP id a12mr3310838ejb.288.1561545551480; Wed, 26 Jun 2019 03:39:11 -0700 (PDT) Received: from [192.168.0.63] (84-75-30-51.dclient.hispeed.ch. [84.75.30.51]) by smtp.gmail.com with ESMTPSA id lw5sm2896071ejb.59.2019.06.26.03.39.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 26 Jun 2019 03:39:10 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) In-Reply-To: Date: Wed, 26 Jun 2019 12:39:09 +0200 Cc: Christian Schneider , PHP Internals Content-Transfer-Encoding: quoted-printable Message-ID: References: <6D1026FF-ECF1-4604-91A8-D290D37CC238@cschneid.com> To: Benjamin Morel X-Mailer: Apple Mail (2.3445.104.11) Subject: Re: [PHP-DEV] [RFC] Strict operators directive From: claude.pache@gmail.com (Claude Pache) > Le 26 juin 2019 =C3=A0 11:36, Benjamin Morel = a =C3=A9crit : >=20 >> (...) could be the case depending on a declaration somewhere else in = the > source code. >> That's the confusion Claude and I were talking about: You cannot be = sure > what a very simple line of code does. >=20 > Oh, I see. You mean that only replacing some of the current results = with > TypeErrors would be acceptable; returning a different value would not. > This makes a lot of sense, but once again prevents the language from = slowly > moving towards something different (and better), leaving it stuck in = its > legacy forever. >=20 > I'm starting to believe that a joint effort to fork PHP if the only = way out > :( >=20 > Ben It would be something =E2=80=9Cdifferent=E2=80=9D, but not necessarily = =E2=80=9Cbetter=E2=80=9D. Programmers may intentionally rely on the current semantics when = comparing numeric strings, e.g. in the following cases: * values that are grabbed from a database using a driver that returns = only strings (or nulls); * values that are read from $_POST and that ultimately stems from some = HTML element. ------- It was certainly a fundamental design error to have both implicit type = conversion and operators that did different things based on the type of = their operands. That leads to the infamous `"1" + 1 =3D=3D 11` problem = in JavaScript, or the the "3" < "24" problem in PHP. That could have = been avoided in two ways: * either by forbidding implicit conversion; * or by using different operators for different types (as does Perl). Now, returning to the case of the comparison operators like `<` or `=3D=3D= `. Instead of killing implicit conversion and redefining the meaning of = those operators in cases that are *not* just edge case, it may be = preferable to use the other approach: * in some strict mode, reserve `<`, `=3D=3D` etc. for numeric = comparison, and throw a TypeError one of the operand is not numeric; * If we deem it worth, define a new operators for string comparison. = (Although I=E2=80=99m not really sure it is worth: we have `strcmp()` = and `=3D=3D=3D` for byte-to-byte comparison, and the Collator class for = alphabetical sorting that actually works in languages not restricted to = unaccented latin characters.) =E2=80=94Claude