开发者

Pass on function arguments to a second function

I have two functions, one which parses all the arguments sent to the function and another that actually does something with that information.

So function1() can take in any number of parameters and then uses func_get_args() to get them all and process them to come up with a string. However, I have a function2() which I want to have a similar functio开发者_JS百科n but some extra stuff added after that. Basically, the second function will save a piece of information that would be overwritten by the first to a temporary variable, then execute the first function, and continue with the rest of that function. So how can I send all the parameters that are sent in to function2() to function1() when it's called within the second function? I feel like I might be over-thinking this and there will probably be a simpler way to do it.

EDIT

I call this function:

function2("arg1", "arg2", "arg3");

and inside that function, I need to send those arguments to function1, like so:

function2() {
    $old = $this->name;
    function1("arg1", "arg2", "arg3");
}

and function1 will do it's processing so function2 can continue. The first function changes the name variable in the class, so I need to temporarily store it beforehand (I don't need it anymore after the function completes). So basically we're just taking the arguments sent to function2 and plugging them into function1.


I'm not sure I understand correctly... but I think you should add call_user_func_array("function1", func_get_args()) to function2()


That your attempt at a solution to the problem is so difficult to describe strongly suggests it is not an ideal approach.

Your problem description suggests at the notion of processing data set with two distinct but related functions. You talk of a temporary variable being operated upon by both functions and, possibly, both functions calling each other.

This points towards the need for a class to wrap these sets of operations, with one or more properties required to hold the original dataset, the output dataset and any number of temporary variables and a clear set of methods to perform the required operations.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜