Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

183
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda