Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

201
Views
Is late static binding in PHP 8.1 trait members deprecated?

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).

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!