dimanche 1 décembre 2019

PHP: A static function being used is nowhere to be found in the class definition.. How do I locate it?

I was trying to understand some PHP functions in Easyblog(a Joomla component), I came across these lines:

public function getDisplay(EasyBlogPost &$post)
{
    $fields = EB::fields();

    // I inject the following 4 lines in order to find where static function "fields" was defined
    $sss = new ReflectionClass('EB'); 
    var_dump($sss->getMethod('fields');
    var_dump($sss->getMethods(ReflectionMethod::IS_STATIC));
    var_dump($sss->getMethod('init'); 

    $field = $fields->get($this->type);

    return $field->display($this, $post);
}

I was trying to find the definition of the static function fields. I was able to find the file where class EB is defined, the first lines looks like this:

class EB
{
    public static $headersLoaded = array();

    /**
     * Initializes EasyBlog's javascript framework
     *
     * @since   5.1
     * @access  public
     */
    public static function init($section = 'site')
    {
        // Determines if we should compile the javascripts on the site
        $app = JFactory::getApplication();
        $input = $app->input;
        $compile = $input->get('compile', false, 'bool');
    ....

But in the file there is no such function called fields, and as you can see class EB doesn't inherit or implement any other class. I then turn to use ReflectionClass, but var_dump($sss->getMethod('fields'); returns an error saying "no method fields", while var_dump($sss->getMethod('init'); does return information about a static function(init) that is defined in the file. Also I tried var_dump($sss->getMethods(ReflectionMethod::IS_STATIC)); according to PHP get static methods, but among the static function array returned, I can't find this "fields" function. I also did a in-text search for function fields( against the whole application, but nothing related was found.

Now this is totally beyond my understanding. SO wouldn't allow me to post here the whole file where class EB is defined, but can anyone explain to me why my approach fails in finding the definition? Can a static function be created dynamically during runtime? If so, how do I find it?





Aucun commentaire:

Enregistrer un commentaire