Z
Z
zeuss562017-03-29 15:24:15
PHP
zeuss56, 2017-03-29 15:24:15

Why can't a static method be called on a context variable containing the class name?

Such a thing:

<?php
class AutoLoader
{
    protected $classname;
    const classFolder = 'Class/';

    private function __construct($classname) {
        $this->classname = $classname;
    }

    protected function Test() {
        return method_exists($this->classname, '__test') ? $this->classname::__test() : true; // unexpected "::" operator at this line.
    }

    protected function GetFilePath() {
        return self::classFolder.str_replace('\\', DIRECTORY_SEPARATOR, $this->classname);
    }

    public static function Load($classname) {
        $this = new self($classname);
        $filepath = self::GetFilePath();
        return file_exists($filepath) && include_once($filepath) && self::Test();
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Aksentiev, 2017-03-29
@Sanasol

stop sawing bikes https://github.com/php-fig/fig-standards/blob/mast...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question