Re: #[Deprecated] Attribute
| From: | Daniel Scherzer | Date: | Wed, 28 May 2025 04:54:22 +0000 |
| Subject: | Re: #[Deprecated] Attribute | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-127491@lists.php.net to get a copy of this message | ||
On Tue, May 27, 2025 at 9:41 PM Ben Ramsey <ramsey@php.net> wrote:
>
> Last night, I identified a need for
#[Deprecated] on a userland
> class in
> one of my libraries, but I had to settle on @deprecated for the
> widest
> range of compatibility.
>
> Has there been anymore thought on putting together an implementation for
> this? I’m happy to draft an RFC if someone is able to help with the
> implementation. I don’t understand the complexities around the
> implementation, but is this something that could make it into 8.5, provided
> an RFC vote passes?
>
> Cheers,
> Ben
>
>
I'd be willing to work on the implementation, but what I'm wondering is
what exactly it would mean to deprecate a class. Without a clear idea of
the goal, I didn't include this in
https://news-web.php.net/php.internals/127305
even though I had considered
it. Would a deprecated class
* Emit warnings when constructed? Just deprecate the constructor,
https://3v4l.org/DNrqm
* Emit warnings when used as a type? But we allow types to include classes
that don't exist (https://3v4l.org/pdkbv) so needing to look up the types
that are declared to emit warnings (rather than just when used to verify
that the type is respected) would presumably have a performance impact.
* Emit warnings when extended? I suggested that in my email a few weeks
ago, and when I have time I was going to look into that - I was thinking
something like #[\WillBeFinal] that would work for classes, methods,
properties, and constants, and would emit warnings just like
#[\Deprecated] but not when a method is called or a constant is used,
just when things are overridden
What were you thinking in terms of desired semantics?
--Daniel