Re: [RFC] [Discussion] #[\Deprecated] for interfaces

From: Date: Tue, 24 Nov 2026 20:00:14 +0000
Subject: Re: [RFC] [Discussion] #[\Deprecated] for interfaces
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-133217@lists.php.net to get a copy of this message
Hi Tim, On Mon, Nov 23, 2026 at 2:52 PM Tim Düsterhus <tim@bastelstu.be> wrote: > Hi > > On 2026-11-23 23:25, Daniel Scherzer wrote: > > Fixed "type declarations", and added rejected features for the > > reasoning. > > Thank you. That mostly looks good to me, but I don't think “Similarly to > the handling of instanceof, type declarations do not require specified > classes to exist” is quite correct: In case of overridden methods the > types need to be available to perform LSP checks: > > class Foo { > public function m(): X { } > } > > class Bar extends Foo { > public function m(): Y { } > } > > prints “Could not check compatibility between Bar::m(): Y and Foo::m(): > X, because class Y is not available” > > So emitting the warning for parameter/return types could potentially > allow for a gradual migration that preserves LSP. A child class could > drop the interface from its return type first (and a parent class from > parameter types). I don't think this will be particularly common in the > real world, though. And of course one would still have the warning when > loading classes that implement the deprecated interface (which will > happen during object instantiation to return or pass the object in > question), so that is probably just sufficient to become aware of the > interface being deprecated. And IDEs / Static Analyzers are of course > free to provide additional diagnostics. > > For completeness: Type declarations also apply to property types (and > typed class constants). > I tweaked this a bit, type declarations don't *always* require the specified types to exist. Included a mention of properties and constants. > > >> My suggestion would thus be to suppress any deprecations “higher” in > >> the > >> type hierarchy if the interface (or in future scope class) is > >> deprecated > >> itself. So the second example would just emit the deprecation for > >> ChildInterface, but not the one for BaseInterface. > >> > >> […] > >> > > > > I think this might be a footgun. Consider if the starting situation was > > > > ``` > > interface BaseInterface {} > > > > #[\Deprecated] > > interface ChildInterface extends BaseInterface {} > > ``` > > > > where the two interfaces are defined in different libraries, and the > > ChildInterface is deprecated for unrelated reasons. If the > > BaseInterface > > were to become deprecated in the upstream library, the downstream > > library > > wouldn't have any warning. > > Would that be an issue though? If the ChildInterface is already > deprecated, it is slated to go away either way. So it implementing an > interface that then later is deprecated for the rest of its “natural > lifetime” might just be okay. Now the base library might perform the > actual removal before the child library does and this might result in a > breaking change without “heads up” when updating the base library to a > new (major) version. But either way it's not really actionable by the > child library author, since the child interface is already deprecated > and it can't just stop implementing the base interface, since that's a > breaking change. > Hmm, I see what you're saying, though I'm not sure that the fact that "it's not really actionable" is a reason to always hide the deprecation notice from the child library. Anyone else have thoughts? > > Best regards > Tim Düsterhus > -Daniel

« previous php.internals (#133217) next »