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

264
Vistas
Callable function as PHP class property

Evaluating a PHP library I found the following code, which seemed to me to be redundant, it makes me think

Why would you want a class to have callable property?

class OpenIDConnectClient
{
    ...

    /**
     * @var callable validator function for issuer claim
     */
    private $issuerValidator;
    
    ...
    
    public function __construct($provider_url = null, $client_id = null, $client_secret = null, $issuer = null) {
        
        ...
        
        $this->issuerValidator = function($iss){
            return ($iss === $this->getIssuer() || $iss === $this->getWellKnownIssuer() || $iss === $this->getWellKnownIssuer(true));
        };
    }
    
    ...
    
}

In the above example the callable property will be the same every time, so it is not about being dynamic, there seems no need to instantiate this in the constructor either, and why not just make it a method of the class?

Addendum Why on PHP Type declarations docs does it say this (emphasis mine):

callable - The value must be a valid callable. Cannot be used as a class property type declaration.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

On line 1318 you can see:

public function setIssuerValidator($issuerValidator){
    $this->issuerValidator = $issuerValidator;
}

this means that you are allowed to change the validator, thus providing the availability to change the property (and validation) without the hassle that you need to create your own class which extends OpenIDConnectClient and overrides the default validator (if you'd use a method instead of the callable property)

Thanks to @DarkBee for the edit

over 4 years ago · Santiago Trujillo Denunciar
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