Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120543 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 56790 invoked from network); 8 Jun 2023 18:45:00 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 8 Jun 2023 18:45:00 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3EAF8180553 for ; Thu, 8 Jun 2023 11:44:59 -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.6 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS34011 80.237.132.0/24 X-Spam-Virus: No X-Envelope-From: Received: from wp160.webpack.hosteurope.de (wp160.webpack.hosteurope.de [80.237.132.167]) (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 ; Thu, 8 Jun 2023 11:44:58 -0700 (PDT) Received: from [2a02:8109:9d40:1d44:40b6:f5d3:c567:d46c]; authenticated by wp160.webpack.hosteurope.de running ExIM with esmtpsa (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) id 1q7Kcy-0003DA-MZ; Thu, 08 Jun 2023 20:44:56 +0200 Message-ID: <9f85eb37-69d5-6861-d6e3-519f4696f6ff@mabe.berlin> Date: Thu, 8 Jun 2023 20:44:56 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 To: internals@lists.php.net References: <5b37626b-1157-e453-d434-4a68916dafc8@mabe.berlin> Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-bounce-key: webpack.hosteurope.de;marc@mabe.berlin;1686249899;dcf70994; X-HE-SMSGID: 1q7Kcy-0003DA-MZ Subject: Re: [PHP-DEV] [RFC] [VOTE] Define proper semantics for range() function From: marc@mabe.berlin (Marc) On 08.06.23 13:16, G. P. B. wrote: > On Thu, 8 Jun 2023 at 07:35, Marc wrote: > >> sorry for speaking up so late but I think the following change is a >> mistake and unexpected: >> >> > Calls to range() that have integer boundaries but a float step that >> is compatible as an integer will now return an array of integers instead >> of an array of floats: >> >> var_dump( range(1, 5, 2.0) ); >> /* New Behaviour */ >> array(3) { >> [0]=> >> int(1) >> [1]=> >> int(3) >> [2]=> >> int(5) >> } >> /* Current Behaviour */ >> array(3) { >> [0]=> >> float(1) >> [1]=> >> float(3) >> [2]=> >> float(5) >> } >> >> The problem I see with this is that the return type changes from float >> to int "magically" based on the value of the step. >> range(1, 5, 2.0) // list range(1, 5, 2.1) // list >> >> In my opinion, no matter, if start, end or step is a float the result >> should be a list. >> > A list is compatible and interpretable as a list so this only I > slight change in output and has effectively no BC break when using the > values generated by range(). > Moreover, this change is needed to make calls such as range("a", "z", 3.0) > work as intended. > I.e. generating a list of characters instead of generating the list [0.0] > by attempting to cast the strings to floats. > > Moreover, considering the return type is already pretty magical, supporting > this specific case would add even more complexity to the implementation, > and this has effectively no BC break, I will not change this detail. > More so that the RFC is currently in voting and cannot be amended. Thanks for your explanation. Now it makes more sense to me. Marc