Re: [RFC] Allow object keys in arrays
| From: | Pierre R. | Date: | Tue, 12 Jan 2021 18:43:30 +0000 |
| Subject: | Re: [RFC] Allow object keys in arrays | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-112858@lists.php.net to get a copy of this message | ||
Le 12/01/2021 à 17:35, Ilija Tovilo a écrit :
Hi Marco On Tue, Jan 12, 2021 at 5:19 PM Marco Pivetta <ocramius@gmail.com> wrote: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. -- PierreOn Mon, Jan 11, 2021, 15:29 Nikita Popov <nikita.ppv@gmail.com> wrote: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.Hi internals, I would like to present a draft RFC for allowing object keys in arrays: https://wiki.php.net/rfc/object_keys_in_arraysOverall, 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 anarrayis given, `foreach ($array as $key => )produces a$keyif typestring|int`. While this assumption does not hold true foriterable(notablySplObjectStorage,Generator), it's still quite a jump to break it here, so it would probably require scheduling such a feature for 9.0.