Hi Marco On Tue, Jan 12, 2021 at 5:19 PM Marco Pivetta <ocram...@gmail.com> wrote:
> On Mon, Jan 11, 2021, 15:29 Nikita Popov <nikita....@gmail.com> 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. Ilija On Tue, Jan 12, 2021 at 5:19 PM Marco Pivetta <ocram...@gmail.com> wrote: > Hi Nikita, > > On Mon, Jan 11, 2021, 15:29 Nikita Popov <nikita....@gmail.com> 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 > > > > The specification in the RFC is incomplete, and primarily focussed on > what > > impact this has from an internal perspective. > > https://github.com/php/php-src/pull/6588 is a draft implementation that > > illustrates the necessary changes. > > > > The primary motivation, and reason why I am looking into this now, is > that > > the current enum proposal is based on objects, and I consider it somewhat > > important that enum values can also work as array keys. > > > > From a technical perspective, this also lays the groundwork for > supporting > > other key types in the future, e.g. if we wish to switch PHP to use > > arbitrary-precision integers. > > > > 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. > > > >