Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112853 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 77935 invoked from network); 12 Jan 2021 16:57:36 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 12 Jan 2021 16:57:36 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3FB5C18053D for ; Tue, 12 Jan 2021 08:35:36 -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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-yb1-f174.google.com (mail-yb1-f174.google.com [209.85.219.174]) (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 08:35:35 -0800 (PST) Received: by mail-yb1-f174.google.com with SMTP id g4so1318254ybo.11 for ; Tue, 12 Jan 2021 08:35:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=E/IlX8tEb+mBZAfquwKEIMqWTglUvQRuDfuNqfFPPnI=; b=BThYwC5w5Ci1fmQCakl6uY1EpXLG/BzQgfpw0ff2/wI9OEREwOD7oIHTC17C1Tc6GT PZkAS11lCDRcXYAaGga/a+5Wk4VZGhdyalxX3erakAtyz52Ma+6t3BSx2nykO1eQwiPf uswzWpk7Dl+S3Jg1t+qS6AMG/U6K+eIoy3CAOuwZiHZO22n9X2vOg8LfWX4z3QCNHGyb B+JbPA4YChf/0WxZvAWiuDaCOhfIIZ4hHFQ1DxPVjaml3pO5EBTuBpwoHh/kwUv1+irK ApIdsLIc8SIEUwW4r9XY38c4SodqTQtaw6vcILmW1LbPiuBKPt++W5LioSR3Tu7RdV8l AM/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=E/IlX8tEb+mBZAfquwKEIMqWTglUvQRuDfuNqfFPPnI=; b=E7eifLFPXg0hxiTSKnERmYIoTWCLGbNXZtkuHE5maCPyo+z7HlJlDdUWmW/+jmIRjw M6mrQS8uv9Qkdg1EDHSR5cxRUldabAUYF9m0u92Gli6RYfNa1nJXf0i7VhyD65a9YIwg LUYTp4CgjxS6xQTgfNthG+oPIHOfycbJPi1C7GMm1JAWyk3xmfwuZfvG05JIYs6jwFuu lqZvAGyg78FUJZWef+CtguzG+gSXklTajLY/9tljWdhQhEwucgsXkvyooZUWtdfHKGmm FCR3VdkU33HRi3TDVBYz9orcT12liKTxO3pRwBNqvAM8GC1qMHc75wDMKbKN4zwRi0er wOeg== X-Gm-Message-State: AOAM531wjxRmxufEYHSjH4fah8H9LvFRhiJFp8DoRlu9bc0gOtzgJnfE CZpb1nharncQmPho5nV/Ae6AouMZoXMOIGZ9VqOkaRPtVxI9RQ== X-Google-Smtp-Source: ABdhPJxSdjTe23RSXkXSsqjid7oXazJ3NHHwQSaSnunckICKfY4byEioJsFOTBc6uzIBW2u6NaAunR8jO3Enn0RFD6Y= X-Received: by 2002:a25:778c:: with SMTP id s134mr290238ybc.411.1610469334634; Tue, 12 Jan 2021 08:35:34 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 12 Jan 2021 17:35:23 +0100 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="0000000000009cd51405b8b69c8e" Subject: Re: [PHP-DEV] [RFC] Allow object keys in arrays From: tovilo.ilija@gmail.com (Ilija Tovilo) --0000000000009cd51405b8b69c8e Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 =F0=9F=A4=94 > > The basic assumption is that, when an `array` is given, `foreach ($array = as > $key =3D> )` 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 her= e, > 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 wrote: > Hi Nikita, > > 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 > > > > 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 somewh= at > > 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 =F0=9F=A4=94 > > The basic assumption is that, when an `array` is given, `foreach ($array = as > $key =3D> )` 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 her= e, > so it would probably require scheduling such a feature for 9.0. > > > > --0000000000009cd51405b8b69c8e--