Hi internals,
I'd like to start the discussion for a new RFC about being able to mark interfaces as deprecated.
- RFC: https://wiki.php.net/rfc/deprecated_interfaces
- Implementation: https://github.com/php/php-src/pull/21998
Thanks,
-Daniel
Quoted text · 6 lines
Hi internals,
I'd like to start the discussion for a new RFC about being able to mark interfaces as deprecated.
- RFC: https://wiki.php.net/rfc/deprecated_interfaces
- Implementation: https://github.com/php/php-src/pull/21998
Thanks,
-Daniel
I somehow didn't even realize this wasn't already supported from the beginning. Yes, this is an obvious addition.
--Larry Garfield
Hi
I'd like to start the discussion for a new RFC about being able to mark interfaces as deprecated.
- RFC: https://wiki.php.net/rfc/deprecated_interfaces
- Implementation: https://github.com/php/php-src/pull/21998
I could swear that the discussion for this RFC had already started, perhaps it was just mentioned as future scope or got a passing mention in some other discussion instead. Anyway :-)
-
There is a typo in the “Comparison” table: You dropped the
pin “ImlementsBase” (and the others). -
I just added the “Abstain” option to the widget for you. The RFC probably predates that policy change.
-
The proposal makes sense to me and I agree that there is no room for further “improvements” regarding deprecating interfaces. Extending an interface and implementing an interface is the two places where an interface actively gets used.
Neither instanceof or using an interface in a type declaration should warn, since there is no way to avoid the deprecation there without actually making a breaking change. Those are “passive” consumers of an interface. It probably makes sense to at least spell out in the RFC how these consumers were considered and why they don't emit the deprecation notice.
Best regards
Tim Düsterhus
Hi
Quoted text · 6 lines
Hi
I'd like to start the discussion for a new RFC about being able to mark interfaces as deprecated.
- RFC: https://wiki.php.net/rfc/deprecated_interfaces
- Implementation: https://github.com/php/php-src/pull/21998
I could swear that the discussion for this RFC had already started, perhaps it was just mentioned as future scope or got a passing mention in some other discussion instead. Anyway :-)
- There is a typo in the “Comparison” table: You dropped the
pin “ImlementsBase” (and the others).
Fixed
- I just added the “Abstain” option to the widget for you. The RFC probably predates that policy change.
Thanks, the RFC was created back in May but I think I just started with a copy from my deprecated traits RFC so that might be why it was missing.
- The proposal makes sense to me and I agree that there is no room for further “improvements” regarding deprecating interfaces. Extending an interface and implementing an interface is the two places where an interface actively gets used.
Neither
instanceofor using an interface in a type declaration should warn, since there is no way to avoid the deprecation there without actually making a breaking change. Those are “passive” consumers of an interface. It probably makes sense to at least spell out in the RFC how these consumers were considered and why they don't emit the deprecation notice.
I added a note that these do not trigger deprecation warnings.
Best regards
Tim Düsterhus
-Daniel
Hi
Quoted text · 7 lines
- The proposal makes sense to me and I agree that there is no room for
further “improvements” regarding deprecating interfaces. Extending an interface and implementing an interface is the two places where an interface actively gets used.Neither
instanceofor using an interface in a type declaration should
warn, since there is no way to avoid the deprecation there without actually making a breaking change. Those are “passive” consumers of an interface. It probably makes sense to at least spell out in the RFC how
these consumers were considered and why they don't emit the deprecation
notice.I added a note that these do not trigger deprecation warnings.
Pet peeve of mine: The RFC says “typehint”. It should read “type declaration”. Those are not hints, they are enforced.
I would also like to ask for some blurb of justification of why they don't trigger a deprecation for public record of the decision making. If you agree with my arguments, you can put them (more eloquently phrased :-)) into the RFC texts.
I also realized another situation where the warning could potentially end up being quite noisy. Using your example:
#[\Deprecated]
interface BaseInterface {}
interface ChildInterface extends BaseInterface {}
class ImplementsChild implements ChildInterface {}
Consider that both interfaces are defined in (different) libraries. As a user of ChildInterface I can't directly do anything about the deprecation, and should not: ChildInterface is not deprecated. But if the author of the ChildInterface library now does an update and deprecates its ChildInterface in response to the upstream deprecation:
#[\Deprecated]
interface BaseInterface {}
#[\Deprecated]
interface ChildInterface extends BaseInterface {}
class ImplementsChild implements ChildInterface {}
Then two deprecation warnings will be emitted, with the BaseInterface one technically being already “acted on” by the library author of ChildInterface by passing along the deprecation. If that makes sense.
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.
Best regards
Tim Düsterhus
Hi Tim,
Quoted text · 10 lines
Hi
- The proposal makes sense to me and I agree that there is no room for
further “improvements” regarding deprecating interfaces. Extending an interface and implementing an interface is the two places where an interface actively gets used.Neither
instanceofor using an interface in a type declaration should
warn, since there is no way to avoid the deprecation there without actually making a breaking change. Those are “passive” consumers of an interface. It probably makes sense to at least spell out in the RFC how
these consumers were considered and why they don't emit the deprecation
notice.I added a note that these do not trigger deprecation warnings.
Pet peeve of mine: The RFC says “typehint”. It should read “type declaration”. Those are not hints, they are enforced.
I would also like to ask for some blurb of justification of why they don't trigger a deprecation for public record of the decision making. If you agree with my arguments, you can put them (more eloquently phrased :-)) into the RFC texts.
Fixed "type declarations", and added rejected features for the reasoning.
Quoted text · 8 lines
I also realized another situation where the warning could potentially end up being quite noisy. Using your example:
#[\Deprecated] interface BaseInterface {} interface ChildInterface extends BaseInterface {} class ImplementsChild implements ChildInterface {}Consider that both interfaces are defined in (different) libraries. As a user of
ChildInterfaceI can't directly do anything about the deprecation, and should not:ChildInterfaceis not deprecated. But if the author of theChildInterfacelibrary now does an update and deprecates itsChildInterfacein response to the upstream deprecation:#[\Deprecated] interface BaseInterface {} #[\Deprecated] interface ChildInterface extends BaseInterface {} class ImplementsChild implements ChildInterface {}Then two deprecation warnings will be emitted, with the
BaseInterfaceone technically being already “acted on” by the library author ofChildInterfaceby passing along the deprecation. If that makes sense.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.
Best regards
Tim Düsterhus
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.
Really, we would want a way to suppress compile-time deprecations, which would be a much more elaborate change - e.g. just reusing @ might not work because we don't want to silence all warnings, just the specific one. I've been thinking vaguely about a system like Rust's expect attribute (
https://doc.rust-lang.org/1.100.0/reference/attributes/diagnostics.html#r-attributes.diagnostics.lint.expect) and how that might work, but that is something for further down the road.
-Daniel
Hi
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).
Quoted text · 9 lines
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.
Best regards
Tim Düsterhus
Hi Tim,
Quoted text · 7 lines
Hi
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.
Quoted text · 10 lines
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
ChildInterfaceis 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