Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119783 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 18168 invoked from network); 30 Mar 2023 02:50:50 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 30 Mar 2023 02:50:50 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 26C601804B3 for ; Wed, 29 Mar 2023 19:50:49 -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.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS20857 136.144.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from outbound11.mail.transip.nl (outbound11.mail.transip.nl [136.144.136.18]) (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 ; Wed, 29 Mar 2023 19:50:48 -0700 (PDT) Received: from submission6.mail.transip.nl (unknown [10.103.8.157]) by outbound11.mail.transip.nl (Postfix) with ESMTP id 4Pn7Fy617WzkQRgj for ; Thu, 30 Mar 2023 04:50:46 +0200 (CEST) Received: from [IPV6:2a02:a450:3eae:1:358c:c963:3a04:73bd] (2a02-a450-3eae-1-358c-c963-3a04-73bd.fixed6.kpn.net [IPv6:2a02:a450:3eae:1:358c:c963:3a04:73bd]) by submission6.mail.transip.nl (Postfix) with ESMTPA id 4Pn7Fx4r0cz12LLD for ; Thu, 30 Mar 2023 04:50:45 +0200 (CEST) Message-ID: Date: Thu, 30 Mar 2023 04:50:46 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Content-Language: nl To: internals@lists.php.net References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: ClueGetter at submission6.mail.transip.nl DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=transip-a; d=demon-angel.eu; t=1680144645; h=from:subject:to: references:in-reply-to:date:mime-version:content-type; bh=BFXdaLZDXO4caaNFqDlSMJNCbW+AXFyEwnVWJ1IU7TQ=; b=KJd94DGFPdzoVWYbKE/XgkKdXsHmh3FzKPIp6bsQ4JA6Ft17RJ7UNHlC0WxAFJFZBHrK0+ dedwuZLh/pxQQM9S13BFXaE+LFXxS6/Q88kJ+6Rh+2+bYrIzb0B7f3klJTUyj7CSaHxnLI Tl24VeU6oCzUbpfypi7dq00T8HR2h9oGnXqI45pm7YLmt03GBNrWxt/2XrH8BFYJ/uGInd CYUbH3yAA/wS6LIT05Bq8YJMPVZYEBaF7N2/SMUjrH3G6X100ckMMPq/hgQ+azacxrmcpm 0G64qxDZu0E9hHeJPismOPHavxzMAJwEaqzgmMlpxw6x8qL2KSRfa7HCwKrs7A== X-Report-Abuse-To: abuse@transip.nl Subject: Re: [PHP-DEV] [RFC] Define proper semantics for range() function From: mark@demon-angel.eu (Mark Baker) On 28/03/2023 00:36, G. P. B. wrote: > Hello internals, > > 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 > > 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. Unlike your changes to the increment operator, I'd love to see this rationalisation put in place, though like many here I don't see problems with using a negative step with decreasing ranges, but would consider it strange for increasing ranges. And I do want to see some case-consistency when working with string ranges. I'd love to see it taken a stage (or two) further; returning an iterable rather than an array (although that would be a bc break); and working with strings (ASCII only) in the same way that the increment operator does, so that range('A', 'IV') would be valid, and return `Z` then `AA`, `AZ` then `BA`, etc. I am slightly surprised that you make no mention of the odd behaviour of mixed alphameric strings, e.g. var_dump(range('A1', 'C5')) which returns a purely alpha array 'A' to 'C'; or var_dump(range('3c', '5e')) which returns numeric (3, 4, 5); or var_dump(range('1', '1e2')) which treates `1e2` as scientific and returns 1..100. -- Mark Baker