Trait %s used by %s is deprecated%S

Description

PHP 8.4 introduced the #[\Deprecated] attribute to flag functions, methods and class constants as deprecated. PHP 8.5 extends this to traits: a trait declared with #[\Deprecated] emits this deprecation notice as soon as another class use-s it, pinpointing the class doing the using.

The optional since and message arguments of the attribute are appended to the notice, for example “ since 1.0, use LoggerTrait instead”, to help locate a replacement.

Example

<?php

#[\Deprecated(message: 'use LoggerTrait instead', since: '1.0')]
trait DeprecatedLoggingTrait {
    public function log(string $message): void {
        echo $message, PHP_EOL;
    }
}

class Service {
    use DeprecatedLoggingTrait;
}

?>

Literal Examples

  • Trait DeprecatedLoggingTrait used by Service is deprecated since 1.0, use LoggerTrait instead

Solutions

  • Stop using the deprecated trait and switch to the alternative mentioned in the deprecation message.

  • If you own the trait, keep the #[\Deprecated] attribute until the trait is actually removed, so callers get a clear migration path.

See Also