Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:106079 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 63805 invoked from network); 26 Jun 2019 23:41:40 -0000 Received: from unknown (HELO mail-ot1-f41.google.com) (209.85.210.41) by pb1.pair.com with SMTP; 26 Jun 2019 23:41:40 -0000 Received: by mail-ot1-f41.google.com with SMTP id q20so1679655otl.0 for ; Wed, 26 Jun 2019 13:58:09 -0700 (PDT) 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; bh=dfcFea4+2Ud6iSSzPXZAhuP/PB+SLEYuJ1ttA9Dz6vk=; b=ojdAXGunjDwolAe28fOKA84uuRZI0m+V05duHzSXQ1Ydd0qOq1U41aXv7pFeWmdKAz xcuOulWFlUAq5ONIA81OId9bdZgKBzH0NdMQtW4580Te1gHGqohNtFqwy0QuXPmD0LZ2 muJCxtwpQE+J4Fz/wlY+/Rk0tEC3QfjZBmvGPtNTR5dVxgqBJ2x2uNh4m3TrP84nSWRA f/zMSxw8+36IdehGjVizcnrB2JTQHMIBIyHo2/PIdrZNEpd6l/49OOK2mGWdKc121BLw B3T35w92VonRc7G/CB/Sdz/GBsKngO8fqfxM1O3k9ex/GoRgh3ZQdS295pvi5P+gFBZN aWew== 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; bh=dfcFea4+2Ud6iSSzPXZAhuP/PB+SLEYuJ1ttA9Dz6vk=; b=LYCRe4IkkvTv/owqMgrDJbeMYcgFCNLMbv7RYXlwoh8+BO1l4U51eowkAItaYEJIJa yZ/95O7vV66GdAhtbYuH/8EN2HNTAMmTlAhgRkJngRKp57Q0ZYvNDHbPidMvGRsK/8iq hdt2jjUq/F4ajAtc9he3A65jKaP4SsjXw3XCDtdTBD8J8X7/pNvEjkN7f8txh/Dupvxa I+wyJKbrHu5xfV7w02zH9isTwLDy+zzghEwhPhsuq6Gi+XmO0L2XKkVeZj6/R6M5R60s qOuOvT8HeUwV9e/YeklV6Jk1kn+plFsKapRO5qZjXcsDOT0Xml7Jyn7PBwf6gVdzCztA 5Z+g== X-Gm-Message-State: APjAAAUQdf41h3irdnmPhSKG8DoDZ6LYch6KDq9PuCFrBW3By0GTu8cs TLZttRYe72UQ7yUYpIqvlHHyvAz8n+3LrO/dyO65rLIS2jA= X-Google-Smtp-Source: APXvYqwk4iULftG1Lh1oegvkrYZF2fAbJU2O9Tk0ijrIRPVfF+4cfmMkdJMQy+7sN1d1rRQ6k2rR03s0uQWiR9qokdI= X-Received: by 2002:a9d:6042:: with SMTP id v2mr224679otj.73.1561582688361; Wed, 26 Jun 2019 13:58:08 -0700 (PDT) MIME-Version: 1.0 References: <6D1026FF-ECF1-4604-91A8-D290D37CC238@cschneid.com> In-Reply-To: Date: Wed, 26 Jun 2019 22:57:57 +0200 Message-ID: To: PHP Internals Content-Type: multipart/alternative; boundary="0000000000006d641c058c404dce" Subject: Re: [PHP-DEV] [RFC] Strict operators directive From: arnold.adaniels.nl@gmail.com (Arnold Daniels) --0000000000006d641c058c404dce Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Jun 26, 2019 at 1:46 PM Benjamin Morel wrote: > > * in some strict mode, reserve `<`, `=3D=3D` etc. for numeric compariso= n, 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.) > > It's true that string comparison (sorting) is a much harder problem that > cannot be solved without additional knowledge of the encoding of the > string; so I agree that it might be better to just throw a TypeError when > comparing strings, and leave the user with an operator that only works on > numbers, and explicitly use dedicated functions when comparing strings. > > This makes sense for "<", "<=3D", ">", ">=3D", but what about "=3D=3D" an= d "!=3D"? > > Currently, "11" =3D=3D "11.0"; what would this yield under the new propos= al? > > - leave it as is: return true in this case =3D> contradicts the whole pur= pose > of the new proposal > - throw a TypeError when performing the above comparison =3D> not accepta= ble > either I guess; every language allows =3D=3D and !=3D on strings, forcing= to use > strict comparison operators is a bit weird here. > - change the semantics to return false when both operands are strings, an= d > don't match =3D> not acceptable to you as you cannot know what a line of = code > does without checking the header > > What would you suggest here? > > Ben > PHP considers a string as a simple byte array. I want to stress that any discussion about character sets or collations is beyond the scope of this RFC. The directive only affects the result of comparing two numeric strings and non-numeric strings. As such, the RFC assumes the current result of comparing non-numeric strings to be 100% correct. To those who disagree with this assumption; please create a separate RFC to discuss this topic and do not take it into consideration in regards to the strict_operators RFC. --- The RFC is modeled after `strict_types`, so to quote part of its motivation "... this RFC proposes a fourth approach: per-file strict or weak type-checking. This has the following advantages: People can choose the type checking model that suits them best, which means this approach should hopefully placate both the strict and weak type checking camps. ..." Take under consideration that the use of `strict_operators` is optional. Those who are inclined to use it consider the current behavior of implicit type casting to be problematic. As such, I imagine that this group does not (want to) use code that exploits this behavior. Those who do not find the current behavior problematic will typically not use the directive and thus are unaffected by it. Disallowing all relational operators for strings is too radical and primarily caters towards those who aren't inclined to use the directive in the first place. In short; it's a compromise that makes nobody happy. The RFC will take the following stance; The directive is catering towards those that find implicit casting by relational operators on two operands of the same type, purely based on the value of those operands, very undesirable. For the audience that's inclined to use the directive, any issues that come from copy/pasting code that exploits this behavior are considered acceptable and should be solved. --- I've added two discussion points to the RFC based on the discussed concerns= . Arnold --0000000000006d641c058c404dce--