On Tue, Jun 25, 2024 at 1:00 AM Alex Wells <autau...@gmail.com> wrote:

>
> a static class member can never implement an interface's contract
>

Well, PHP is a weird one here compared to other languages

Interfaces can contain contracts for static methods and they are checked
just like usual non-static methods.
Example: https://3v4l.org/8cuXW

With late static binding, you can define static abstract methods and
basically do code reuse through inheritance.
Example: https://3v4l.org/pid7W

I'm not saying I would ever use such a thing, just that they exist and
others might find them useful so why build limits around it?
A limit is just extra code to maintain and make sure you use it
consistently.

I believe that a static class should have the principle of no allowed
instance and only static methods, without any impact on inheritance:
- There can be a static interface and a static abstract class
- A static class can extend a non-static class, or implement an interface
or abstract class as long as it does not require to implement a non-static
method.
- A static class can be extended only by another static class
- As static interface can be extended only by a static class

Basically, when a static class gets into the inheritance chain, all the
extending classes will be static and there is a guarantee that there will
never be an instance of that class.

Making sure a static class does just that, limiting the methods and
properties in it to only be static, will keep things simpler going forward
when thinking about interactions with other features.
Like readonly static class would not work right now, but it will work if
readonly will be implemented for static properties, and that should be
doable effortless.

Alex

Reply via email to