Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120211 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 51908 invoked from network); 8 May 2023 09:25:07 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 8 May 2023 09:25:07 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9FD55180044 for ; Mon, 8 May 2023 02:25:05 -0700 (PDT) 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, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 8 May 2023 02:25:02 -0700 (PDT) Received: by mail-pg1-f175.google.com with SMTP id 41be03b00d2f7-51b4ef5378bso3873589a12.1 for ; Mon, 08 May 2023 02:25:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683537901; x=1686129901; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=W+5SGytaa2TmWQkBU8mo+Zeu2O7xurj0SJGDyj0k3aU=; b=E17cag6k8QWam+fJWzqjjsFU7NrpUA/fhM02G/HQi9UYASrhuJI3Gl4SyzLW1OtNG1 0x/zDiPrRD71FvMP8wBbo0xTLsmpWZcZ5Dn9pAS9uu+itoh5CxuExMCT991e0SFFGoDN uKnK7L66l9mnyrIV2HrblLX4lB4Flm/OY/Ii53xIMkpjhsSWxkr57y0Evx0EexKrG/Cx 7ph84aPkEgjEpUlNKK1VQXeqITDPgULKk9gQT2fu0MHTjYH1N1XFjdN9ar0rCVwq5VTv XS6aaYBc9L+DJHn4ZM9cCgZjWRY9phxZ2ETFDv7LH1tTdv7i+ZRJalvsY11SuTaeVc+5 99Uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683537901; x=1686129901; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=W+5SGytaa2TmWQkBU8mo+Zeu2O7xurj0SJGDyj0k3aU=; b=Akw1RknoPnyizYj2wXx5nBDFNK3KevbmlujfLh2rkR6xbKiELzTo2OIujmcUFewmmz w5Zzu+2MGEcKwdkgo3+fM70Z047akR07TosZ2NaMfMqz6X/feT6et0DYSubWh1Z9Udop kQ+eGHkrikLip95Cvs3xLXJACxuZNlmOigrI7Z0c+oYmEBSKO4ikfJb+ytwBbFWO0WI7 o9W4dkuTnsS/CQ846wb4Ed0CkB7U47ZSrnB2D0rfywdT6JoauAFj5F0SwzgRJ4FwAV4W CFVIZHN+kaj/OosNIWcS+FdVC/IY1zktiWE2/YdOATeKpmg4i6sIAAf4bC1pxjgjxIrI Fqjw== X-Gm-Message-State: AC+VfDxC6VYl4HPWTWG8MnwNnrz1Nw4f9f1Zwq3UQ0YjjxkioUwUrYr6 47QZ3r4AeeTr/2mqdExY99QVPj9WGbfidWsDhhVVCS2dVsE= X-Google-Smtp-Source: ACHHUZ4yfTHsyV4+lo03hiRKftIodRl5x2tDTXiHKsne/lRbYxHg7efw39Oi2SNGyeMLeqtJW8vUTExOwwCwOBxbX0M= X-Received: by 2002:a05:6a20:8f07:b0:ef:70b:42fc with SMTP id b7-20020a056a208f0700b000ef070b42fcmr12330647pzk.38.1683537900829; Mon, 08 May 2023 02:25:00 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 8 May 2023 10:24:49 +0100 Message-ID: To: Derick Rethans Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000008b7e2605fb2b3646" Subject: Re: [PHP-DEV] [RFC] Define proper semantics for range() function From: george.banyard@gmail.com ("G. P. B.") --0000000000008b7e2605fb2b3646 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, 5 May 2023 at 15:49, Derick Rethans wrote: > On Mon, 27 Mar 2023, G. P. B. wrote: > > > While working on analysing the impact of the changes proposed by > > amending the behaviour of the increment and decrement operators ( > > https://wiki.php.net/rfc/saner-inc-dec-operators) I discovered that > > the range() function has some rather lax behaviour that is very > > unintuitive. > > > > I therefore propose the "Define proper semantics for range() function" > > RFC to address the unintuitive behaviour that sees no usage and/or > > hide bugs: https://wiki.php.net/rfc/proper-range-semantics > > | If $step is a float but is compatible with int interpret it as an > | integer. > > I guess you mean with that "the fraction is '.0'" and "-2^52 < number < > 2^52" ? What is also going to be playing up is the range of $start and > $end itself. > Yes, this is what I mean by "compatible with int". > | Introduce and use a proper ZPP check for int|float|string $start and > | $end parameters, this will cause TypeErrors to be thrown when passing > | objects, resources, and arrays to range(). > > I am not sure whether it wise to disallow resources. These are often > file descriptors and having a range on those *could* make sense? Not > fussed much either way though. > This is not how file/stream resources work. The resource number is not correlated to the file descriptor. The only cases where this is the case are the predefined streams STDIN, STDOUT, and STDERR. This is part of the reason for needing a new function like the file_descriptor() function I'm proposing. [1] > | Throw a ValueError when passing a negative $step for increasing > | ranges. > > I think that's a BC break that is not worthy of making. > There is no impact shown, and it doesn't make sense to pass a negative $step. This can be changed to a deprecation but considering there is no impact I don't see why we should wait. | Emit an E_WARNING when $start or $end has more than one byte. > > Surely only if the string doesn't represent an int or float? > Yes, this was implied. As we are only concerned about the "pure string" case here. But I have clarified this. | var_dump(range(null, 2)); > > I think that safely can be interpreted as range(0, 2) =E2=80=94 I wouldn'= t throw > a deprecation warning for that... but then of course, we do already have > a similar (deprecation) warning for arguments. > The deprecation is just a consequence of finally using ZPP, thus invoking the previously accepted RFC. > > The change propose to throw TypeErrors and ValueErrors for case where I > > couldn't find occurrences in the wild and hide bugs, and emit some > > E_WARNINGs for cases that are hard to detect via static analysis. > > | Target Version: PHP 8.3 > > In my opinion that's not a good thing. There are a fair amount of BC > breaks (beyond the one that I oppose to with nagative steps throwing an > ValyeError), without first having deprecations. IMO, the actual BC > breaks here should become deprecations in 8.X and BC can only be really > broken in 9.0. Disagree, the implementation is already complicated, and trying to support the current absurd behaviour is impractical, especially as no impact has been found. Best regards, George P. Banyard [1] https://wiki.php.net/rfc/file-descriptor-function --0000000000008b7e2605fb2b3646--