PHP 8.4 added the #[\Deprecated] attribute, which makes PHP emit a deprecation when you call a deprecated function or method, or use a deprecated class constant. This RFC from Daniel Scherzer lets you put it on a trait too, so PHP warns whenever a class uses that trait.
How it works
#[\Deprecated] trait DemoTrait {} class DemoClass { use DemoTrait; } // Reports: // Deprecated: Trait DemoTrait used by DemoClass is deprecated in %s on line %d
This helps library authors. You can tell users a trait is going away, and PHP points them to every place they still use it.
A few details:
- The attribute only works on traits. You can't use it on classes, interfaces or enums, even though PHP groups those together elsewhere.
- The warning only fires where a class uses the trait directly. A child of that class doesn't trigger another warning unless it also uses the trait itself.
- You can turn the warning into an exception with an error handler, the same as other deprecations:
set_error_handler('my_error_handler'); // throws ErrorException #[\Deprecated] trait DemoTrait {} class DemoClass { use DemoTrait; } // Fatal error: Uncaught ErrorException: Trait DemoTrait used by DemoClass is deprecated in %s:%d
What it means for existing code
Nothing breaks. PHP itself doesn't ship any traits, so no built-in code is affected. IDEs and static analysis tools will likely want to flag these deprecations before PHP does at runtime.
Later RFCs could support the attribute in more places, like extending a class, implementing an interface or reading a property.
The vote
It passed 20 to 0 on a Yes/No vote that needed a two-thirds majority. Voting closed on August 7, 2025. It targeted PHP 8.5, and the page lists it as implemented.