0

I want to call a function with variable length arguments stored in an array. I noticed that you can do this with call_user_func_array($callback, $array); However it doesn't seem to work on instance variable methods.

class foo{
  $iVar 

  function A{
      $anArray = array(...);
      call_user_func_array(iVar->methodName,$anArray);
  }
}

Any suggestions?

1 Answer 1

1

A couple of things are wrong there. First, iVar is not a constant, so it should begin with a $. And since it is a property of foo, it should be $this->iVar.

Secondly, you cannot pass a function like that. You have to pass it as a callable. So in total, the call should look like this:

call_user_func_array(array($this->iVar, 'methodName'), $anArray);
Sign up to request clarification or add additional context in comments.

Comments

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.