Re: Static class
| From: | Rob Landers | Date: | Sat, 15 Jun 2024 14:52:36 +0000 |
| Subject: | Re: Static class | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-123615@lists.php.net to get a copy of this message | ||
On Sat, Jun 15, 2024, at 16:40, Bilge wrote:
> On 15/06/2024 14:53, Rowan Tommins [IMSoP] wrote:
> > On 15/06/2024 12:16, Bilge wrote:
> >>
> >> I want to introduce the
static keyword at the class
> >> declaration
> >> level. That is, the following would be valid: static class Foo
> >> {}..
> >
> >
> > This has been proposed before, and was rejected at vote. It was nearly
> > 10 years ago, so opinions may have changed, but it would be worth
> > reading through the prior discussion to anticipate or counter the
> > objections raised, and avoid re-treading the same ground.
> >
> > - RFC: https://wiki.php.net/rfc/abstract_final_class
> > - Pre-vote discussion threads:
> > https://externals.io/message/79211 and
> > https://externals.io/message/79338
> > - Final vote thread: https://externals.io/message/79601
> >
> > Searching my list archive, I find that it came up again a few months
> > ago, which I'd entirely forgotten:
> > https://externals.io/message/121717
> >
> > Slightly tangential, but some of the same discussion also came up on
> > these rather lengthy threads about "static class constructors":
> > https://externals.io/message/84602 and
> > https://externals.io/message/85779
> >
> >
> > Regards,
> >
> Hi Rowan,
>
> That's all quite interesting, but I didn't get a good sense of why the
> idea was rejected, other than people didn't like "abstract final" as the
> syntax (thank God). As for why "static" was rejected, as stated, I don't
> get a good sense of it at all, but rather than fall back on the opinions
> of many who are mostly absent among those polled nine years ago, I'd
> rather get a sense of the current sentiment of those present today.
>
> Cheers,
> Bilge
>
I can see these mostly being used for factories, laravel facades, or utility functions. I think they
would probably be useful in some codebases.
I would argue that in the codebases I work in, these types of constructs represent a code smell and
it would be a lot easier to catch via static analysis and prevent. The current trick of using traits
is much harder to catch except during code review.
So, I say “yes please.”
— Rob