1

Is there a way to save the arguments I am going to use in a function into a variable?

Example, if a function requires:

function foo($string, $callback_function) {
    //
}

How can I save

 $arguments = $string, $callback()

So that I can

foo($arguments)

Is this possible? How? And what does this method called?

Thank you very much

1 Answer 1

1

use call_user_func_array http://php.net/manual/en/function.call-user-func-array.php

<?php
$arguments=array($string,$callback);
call_user_func_array('foo',$arguments);
Sign up to request clarification or add additional context in comments.

2 Comments

are there any other method? because the function is a method of a class Model::blah()->foo($arguments); ?
You can call static methods on classes like so: call_user_func_array('Model::blah', $arguments); And on instantiated objects by passing an array: call_user_func_array(array($model,'blah'), $arguments);

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.