1

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 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);
}
1
  • What exactly are you asking here? You say you know what the problem is, so why are you still trying to get it to work using $this? You can't use $this in a static context. Commented Mar 24, 2010 at 16:28

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Sorry I don't understand. As I don't know the number of parameters I am using call_user_func_array. However when I do this I cannot use $this in my controller functions. Is there an alternative function?
@JasonS: Of course you can do. But currently you are passing the class array($this->controller, $function) instead of the object array($controller, $funtion) to the function. That is where your error is.
Ah ofcourse, I couldn't work out what had been changed. Thanks so much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.