Re: [RFC] Improve language coherence for the behaviour of offsets and containers

From: Date: Wed, 10 Jul 2024 00:52:38 +0000
Subject: Re: [RFC] Improve language coherence for the behaviour of offsets and containers
References: 1 2  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
> 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 not exactly sure how I am meant to interpret
> the lack of responses.

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.

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/5c7603f420e3a75a5750b3e54cc95dfdbef7d6e2/src/Line.php#L166
 2. https://github.com/ParvulaCMS/parvula/blob/dcb1876bef70caa14d09e212838a35cb29e23411/core/Models/Config.php#L46

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:

    $container->append($item);

I expect largely they will do:

    $container[] = $item;

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?

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.


Thread (15 messages)

« previous php.internals (#124327) next »