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

261
Views
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 answers
Answer question

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 Report
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!