Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

182
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda