Help understanding PHP5 error

后端 未结 4 486
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-28 08:29

In short.. question is... \"Say what?\" To expand... \"I don\'t get the error\"

Strict Standards: Non-static method Pyro\\Template::preLoad() should not b

相关标签:
4条回答
  • 2021-01-28 08:51

    Like everyone said, the you called the function with as a static method:

    Template::preLoad(xxx)

    The :: means static in PHP. Functions are typically called as static :: or object -> calls.

    The function definition is one or the other:

    public static function preLoad($template, $page)

    Called like: Template::preLoad('admin/courses/index', $this->data);

    OR

    public function preLoad($template, $page)

    Called like Template->preLoad('admin/courses/index', $this->data);

    For reference, a static function is able to be called without instantiating an object. If your function doesn't need an object to run, you could make it static. Basically, this means you can't reference $this in a static method. It will run with the given inputs without having to construct the object.

    0 讨论(0)
  • 2021-01-28 09:03

    preLoad function should be static

    public static function preLoad($template, $page) {
    
    0 讨论(0)
  • 2021-01-28 09:05

    Well the preLoad function is not static. Which means only an object of the class Template can use this method. A static method exists indepedently of any object of the class.

    Template::preLoad is a static call : you didn't create a Template object, then call the preLoad method. So basically, you've got two solutions :

    • Making preLoad static;
    • Creating a Template object, and then call its preLoad function.
    0 讨论(0)
  • 2021-01-28 09:12

    preLoad function isn't static. ti should look like this:

    public static function preLoad($template, $page) {
            ob_start();
    
            include( VIEWS . "{$template}.php");
    
            $buffer = ob_get_contents();
            @ob_end_clean();
            return $buffer;
        }
    
    0 讨论(0)
提交回复
热议问题