website/errors/enum.implementsDeprecatedTrait.md
<?php declare(strict_types = 1);
/** @deprecated Use NewHelper instead */
trait OldHelper
{
public function help(): void
{
// ...
}
}
enum Status implements OldHelper // error
{
case Active;
case Inactive;
}
This error is reported by phpstan/phpstan-deprecation-rules.
The enum references a deprecated trait in its implements clause. The trait has been marked with the @deprecated PHPDoc tag, indicating it is scheduled for removal or replacement. Additionally, traits cannot appear in an implements clause -- only interfaces can be implemented.
Replace the deprecated trait with a non-deprecated interface:
<?php declare(strict_types = 1);
-enum Status implements OldHelper
+enum Status implements NewHelperInterface
{
case Active;
case Inactive;
}
If the trait functionality is needed, use it with the use keyword inside the enum body instead of implements:
<?php declare(strict_types = 1);
-enum Status implements OldHelper
+enum Status
{
+ use NewHelper;
+
case Active;
case Inactive;
}