On Wed, Jul 2, 2025 at 11:00 PM Gina P. Banyard <intern...@gpb.moe> wrote:

> Hello internals,
>
> It is this time of year again where we proposed a list of deprecations to
> add in PHP 8.5:
>
> https://wiki.php.net/rfc/deprecations_php_8_5
>


On the topic of deprecating `__construct()` in interfaces:

I'm thinking about constructors usually like this:
They are functions that are invoked statically (using the `new` keyword) on
the class before the object is created, and they execute on instance level,
after the object is created.

They are called as static methods, and they are very similar to static
factory methods, and for better or worse, static methods are supported in
interfaces.

So, in this sense, I think the pattern of defining a constructor in an
interface is useful.
This way, a factory that receives a class name implementing a specific
interface that defines a constructor will be able to accurately instantiate
that class in a simple way.

One could also argue that the deprecation could be solved easily by
replacing the constructor in the interface with a static factory method.
I think we should talk more on this, and I see that Ilija also touched on
it in his reply while I was drafting mine, with even more details.

Generally, I think that's what would be good for each deprecation, to have
a clear way of solving it noted in the RFC.

-- 
Alex

Reply via email to