Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112858 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 93901 invoked from network); 12 Jan 2021 19:05:33 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 12 Jan 2021 19:05:33 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 21F391804F3 for ; Tue, 12 Jan 2021 10:43:34 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,KHOP_HELO_FCRDNS, SPF_HELO_NONE,SPF_NONE,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from processus.org (ns366368.ip-94-23-14.eu [94.23.14.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 12 Jan 2021 10:43:33 -0800 (PST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by processus.org (Postfix) with ESMTPA id 50F355101324 for ; Tue, 12 Jan 2021 18:43:31 +0000 (UTC) To: internals@lists.php.net References: Message-ID: <708bdb8a-c653-5f7e-7efc-b1c22fefafdd@processus.org> Date: Tue, 12 Jan 2021 19:43:30 +0100 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Authentication-Results: processus.org; auth=pass smtp.auth=pierre-php@processus.org smtp.mailfrom=pierre-php@processus.org X-Spamd-Bar: / Subject: Re: [PHP-DEV] [RFC] Allow object keys in arrays From: pierre-php@processus.org ("Pierre R.") Le 12/01/2021 à 17:35, Ilija Tovilo a écrit : > Hi Marco > > On Tue, Jan 12, 2021 at 5:19 PM Marco Pivetta wrote: > >> On Mon, Jan 11, 2021, 15:29 Nikita Popov wrote: >> >>> Hi internals, >>> >>> I would like to present a draft RFC for allowing object keys in arrays: >>> https://wiki.php.net/rfc/object_keys_in_arrays >> Overall, this is something I always wanted, but adding it means that the >> type of all array functions returning keys widens, which is quite the BC >> hell ? >> >> The basic assumption is that, when an `array` is given, `foreach ($array as >> $key => )` produces a `$key` if type `string|int`. >> >> While this assumption does not hold true for `iterable` (notably >> `SplObjectStorage`, `Generator`), it's still quite a jump to break it here, >> so it would probably require scheduling such a feature for 9.0. >> > Definitely disagree here. Your existing code will continue to work fine > without changes. It is only after passing objects as keys to other > functions with the assumption above that your code breaks. Sure, this will > require code changes for frameworks to handle these cases gracefully but it > won't suddenly break your website that hasn't been touched for years. > > Note that even minor PHP versions have historically not followed strict > semantic versioning. If we did, most PHP features would have to be pushed > back years given PHPs relatively slow release cycle. I don't think that's > desirable for neither PHP developers nor maintainers. I do agree with Marco, lots of generic code manipulating array keys will be prone to failure with such feature, it is a breaking change. Nevertheless, the feature is so appealing that I'm definitely OK with fixing all the things ! Nevertheless, lots of major frameworks and libraries will having tests to write, and fixes to do, and the transition to support will probably be erratic and slow. -- Pierre