There is an existing deprecation notice for PHP8.1 which indicates:
Calling a static method, or accessing a static property directly on a trait is deprecated. Static methods and properties should only be accessed on a class using the trait.
The example given in the associated RFC shows accessing a static member from the trait directly, from outside the trait/class. However, it is ambiguous as to whether this applies to self/static contexts inside of traits. What I'm interested in is whether this deprecation applies to accessing static class members from the trait internally, for example:
trait SupportsArrayBackedValues
{
abstract public static function cases();
public function backedValueArray(): array
{
return array_map(fn($case) => $case->value, static::cases());
}
}
PhpStorm 2021.3.1 displays a deprecation warning as such when using static::cases():
Calling static trait member directly is deprecated. It should only be accessed on a class using the trait.
But I'm unsure if this is legitimate, or a bug in how they're parsing the inspection. The inspection offers to convert to self::cases(), which continues to show a deprecation warning. I can find no issues being tracked in IntelliJ's YouTrack for this issue which indicate it's a bug, however.
If this is indeed a valid inspection notice, is there an appropriate way of implementing the functionality I'm seeking, or more generally, accessing static members of a class from inside a trait? (i.e. in my scenario, converting a backed enumeration to an array of string/integer values, rather than enumeration instances).