1

I am sending parameters as an array in second argument but not able to receive as one array in my receiving function, I can receive but one value as one variable so if have 3 parameters I have define three variables in my receiving function.

 $this->params[] = 'val1';
 $this->params[] = 'val2';

call_user_func_array([$this->controller, $this->method], $this->params);

I am expecting array in $param but getting in chunks like $param $param2

 public function index( $params )
  {
   echo "<pre>";
   var_dump($param);
  }

 public function index( $param1, $param2 )
  {
   echo $param1;
   echo $param2;
  }
3
  • 1
    Just wrap ithe arguments in one more array: call_user_func_array([$this->controller, $this->method], [$this->params]); Commented Apr 2, 2019 at 5:26
  • @MagnusEriksson are you going to answer or close? Looks like you have an answer to post. Commented Apr 2, 2019 at 5:34
  • Isn't the alternative to use call_user_func instead? Commented Apr 2, 2019 at 6:18

1 Answer 1

3

An easy solution to your issue is to simply wrap the arguments in another array:

call_user_func_array([$this->controller, $this->method], [$this->params]);

Then it will pass an array as the first argument to your method.

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.