Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124349 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 860A71A00B7 for ; Wed, 10 Jul 2024 15:05:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1720623995; bh=tpdyOmhtox9KUCZ2NnMpTRMHCAbfjkSmsI2xB6bivuA=; h=Date:To:From:Cc:Subject:In-Reply-To:References:From; b=kVg1UwNEh29z0qbXUAHpTo3qo7MkSldE9JEtGfQ/duqnluy6zOWnwAiyXkdguDO6U CasUtLgqhQpqHwU6Zs0KlFJRyUX2C91Vm3gnfZQ8tkV6GhnnThKVwL1at1ch06p7Sp 6T9ZRCJunrFT+foiRaHgaDhwoTbhDQlfC5cxcOVBCjYr2Nu4NejCoMveEG5QyOKM8x gMrfPzWAHAEAgo+c7JRV9y0ImsaqqBWdGNIiIHwoV8XGOMd5VPbdDvwGEUmRtikuJz 0SOTjjjJ9X/ddnONsW9khM6ydBGUEKMz3BmQHi5rQSNRbZhBKo/OIiqwafmHIl/uyD o4LcXGR09d67Q== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 570F318033A for ; Wed, 10 Jul 2024 15:06:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-4317.proton.ch (mail-4317.proton.ch [185.70.43.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 10 Jul 2024 15:06:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gpb.moe; s=protonmail2; t=1720623904; x=1720883104; bh=tpdyOmhtox9KUCZ2NnMpTRMHCAbfjkSmsI2xB6bivuA=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=Tws3vAQjPygMn0LY+kgXMiMLGkhRpJz68NEwaWPTgDFmsCIISYOe4MvdLc0l/hxLF 8wKkY1meghhzo/vgvfTZdO0hQ9KBneSY5NQjZO6/8B3WodoUItO7CIyAJ82Np/pbdE Ky9T5Ej4CmKF815YKhru0n/D7t6Ad41/PGBEmeQ2ApMhftM9FpzNsZ4WWEmNBZjJa+ t8J8Qu6tEudLCKrXF4yKzHdaTZ7mwBn42QqHwiiJfnj7q4eHUNKPWkgri55qSrW5ai g1X2CgNhyIAwmUoMRM61l4va4CXIGFEeKnA5eDZRv2ugJ2p1NUkS7aFDIcKXqIMlYI Y2pbLgWE5f3cg== Date: Wed, 10 Jul 2024 15:04:58 +0000 To: Levi Morrison Cc: PHP internals Subject: Re: [PHP-DEV] [RFC] Improve language coherence for the behaviour of offsets and containers Message-ID: In-Reply-To: References: Feedback-ID: 96993444:user:proton X-Pm-Message-ID: caadf0fde0b768a6d0461ee96f3f0b0717df06e3 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: internals@gpb.moe ("Gina P. Banyard") On Wednesday, 10 July 2024 at 01:52, Levi Morrison wrote: > > Moreover, I know the traffic on the list has been pretty high, but I do= intend to have this RFC up for voting for inclusion in PHP 8.4, and I'm no= t exactly sure how I am meant to interpret the lack of responses. >=20 >=20 > I am personally strongly in favor of the direction. As mentioned in > the PR, my main concern is honestly quite a small one: I think > `Appendable::append` ought to be renamed. Maybe `Appendable` and > `FetchAppendable` too. >=20 > The reason is that `append` is a common operation on a container type, > which is likely to want to implement these interfaces. I easily > identified a few such things with a quick GitHub search: > 1. https://github.com/pmjones/php-styler/blob/5c7603f420e3a75a5750b3e54cc= 95dfdbef7d6e2/src/Line.php#L166 > 2. https://github.com/ParvulaCMS/parvula/blob/dcb1876bef70caa14d09e212838= a35cb29e23411/core/Models/Config.php#L46 >=20 > Given that I anticipate these methods to largely be called by > handlers, and not by names, I think an easy solution is to just name > this `offsetAppend` to match the other offset operations. For example, > I don't anticipate code doing: >=20 > $container->append($item); >=20 >=20 > I expect largely they will do: >=20 > $container[] =3D $item; >=20 > So it doesn't really matter if the name is `append` or `offsetAppend` > for the main use-case, and thereby we avoid some road bumps on > adoption. Any SPL containers with `append`, such as ArrayObject, can > make it an alias of `offsetAppend`, I think? >=20 > Anyway, this is a minor thing, and I will vote yes regardless of > whether it (and maybe the *Appendable interface names) are changed. > But I do think it would be prudent to change it. It would also match > the `offset*` convention of the other interfaces. Part of the RFC is to deprecate aliases to the dimension handlers, e.g. Spl= ObjectStorage, because those classes are not final, and you can extend the aliased method = and make it behave in whatever way you want. Which causes unintuitive bugs, because if you overwrite SplObjectStorage::c= ontains(), which is currently considered the "canonical" method, you don't actually overwrite the behaviour of isset($obj[$index]) The documentation even indicates that offsetExists is an alias of contains(= ) [1] Considering, one part of the RFC is to get rid of this aliasing, introducin= g it for append() doesn't make sense to me. It should be noted, we have other internal classes that have an append() me= thod that is compatible with the current interface design. One such example is AppendIterator, currently it doesn't implement ArrayAcc= ess because... that doesn't make sense, but it would be quite useful for it= to implement the new Appendable interface (or whatever preferred name). Changing the name of the method on the interface would require introducing = more aliases, something that I don't think is wise. (another class that could benefit from this is the Dom\Element class) Side note: we had issues in the past with SplFileObject having different me= thods names for the same thing being aliased, and just thinking about it ag= ain makes my brain hurt. Moreover, the name 'offsetAppend' is somewhat nonsensical, one appends to a= *container*, the naming here implies to me that I am appending to an offse= t, which to me makes this a bad name. Finally, the whole point of ArrayAccess is to make container types feel mor= e like a normal array, so it seems perfectly normal for me to have append b= e the name of it. Yes there will be some classes that are incompatible with this interface, b= ut I would guess the majority of implementations of an append() method just= take a single value, or a variadic number of values to append to the custo= m container. Both such custom container type implementations would be able to use the in= terface without any major changes. [2] From a quick glance, I can see various classes of Symfony and Laravel that = could add an implementation of Appendable, and just widen the parameter typ= e (truly sad the lack of generics) to allow people to use the $container[] = =3D $value syntax with said class. Requiring a lot of projects to duplicate the implementations of their metho= ds just to support this, and possibly hitting the problem we face with Arra= yObject at a larger scale, seems ill-advised to me. For container types where appending means something more complex, then yes = they cannot use the interface, but regardless of name they would not be abl= e to. And I don't see how them continuing to use "append" as a method name causes= problems. Thus, from my PoV, the only adoption issue is for classes that pass the val= ue by reference to the append() method, which seems to indicate that they n= eed to implement fetchAppend() to grab a reference and then assign the valu= e. Everything considered, I still do not think changing the name of the append= () method is a good idea, will it hurt adoption in the short term for some = classes, yes, but I prefer this than having a large part of the ecosystem n= eeding to create an alias just for some weird cases. Best regards, Gina P. Banyard [1] https://www.php.net/manual/en/splobjectstorage.offsetexists.php [2] https://3v4l.org/E8BcK