开发者

Using $this when not in object context in: php error

I have solved this problem, I just need to know what to do. I get the above error because I just realised that the class is being run as class::function($values) instead of class->function($values).

Does anyone know开发者_Python百科 how to convert this function to instantiate the class then run the function with values?

private function _load($values=null) {

    define('LOADED_CONTROLLER', $this->controller);
    define('LOADED_FUNCTION', $this->function);

    $function = $this->function;

    $controller = new $this->controller;
    ($values == null) ? $controller->$function() : call_user_func_array(array($this->controller, $function), $values);
}


You already instantiate the class:

$controller = new $this->controller;

Just use your $controller also in call_user_func_array:

($values == null) ? $controller->$function() : call_user_func_array(array($controller, $function), $values);

In your code you try to call a static method on the class if $value != null. That of course will result in an error if you use $this in this method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜