On Wed, Jul 16, 2025 at 3:49 AM Rob Landers <rob@bottled.codes> wrote:

>
> Why I haven't proposed it as a separate RFC: with PSR-4 being so popular,
> nobody is going to write one-line files to take advantage of this. Thus,
> when I was going to revisit nested classes later this year (after all the
> release shenanigans and some personal issues), I was planning to add this
> feature to the nested class v2 RFC (again). A lot of feedback I got on
> nested classes was "when would I use this?" -- and I suspect that would be
> a lot of the feedback you'd get here (see: PSR-4). I'm more convinced than
> ever that short constructors and nested classes create a chicken-and-egg
> problem. They only really make sense together; at least with our current
> coding conventions and standards. It will create a longer discussion
> period, but that's fine, IMHO.
>
> If you'd like to continue with this RFC, I'd love to discuss it further
> with you and help you out. I believe it is a bit more than "just" syntax
> sugar, but I'd have to dig out my records implementation.
>
> — Rob
>

I remember PHP from ~2000's and PSR-4 and Composer were probably one of the
biggest improvements to the ecosystem. However, I feel like a "2.0" version
is long overdue. I have participated in some internals discussions that
point out a fact from the other direction: PHP makes no imposition about
file structure. 1-class-per-file is strictly a PSR-4 implementation of a
custom autoloader which we have gotten used to for so long. I would really
love to be able to declare small related classes/interfaces in a single
file much like we can do with Typescript, but the current state of PHP
"register your autoloader however you would like it" vs the current state
of the community "PSR-4 is THE standard", we end up between a rock and a
hard place. I don't particularly enjoy nested classes and how the syntax
and its contexts get involved. Sure it would be nice to have private
classes, but it gets quite cumbersome to have to do it while nesting
classes within classes.

On the other hand, we can see from constructor property promotion that
these little syntax sugar can be such a massive improvement to cognitive
load, readability, writability, etc. I would really love to have something
much like this RFC even if at first I need to do it as a one-line-per-file.
To me, the more interesting chicken-egg problem to address is whether PHP
needs to provide some change to symbols, namespaces, autoloader or if the
community needs to expand PSR-4 in a way that allow us to not reject this
RFC on the basis of "PSR-4 will drastically limit syntax sugar
improvements".

-- 
Marco Deleu

Reply via email to