views:

54

answers:

3

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 function 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.

+4  A: 

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

cristis
+1 that's what I was thinking too
Gordon
+1 - A link to the docs for [`call_user_func_arary`](http://php.net/call_user_func_array) wouldn't hurt :)
gnarf
Yes, this is exactly what I was looking for, I was just thinking about it the wrong way.
animuson
A: 

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.

Jon Cram
A: 

and function1 will do it's processing so function2 can continue.

This seems to imply that you want these functions to be running concurrently?

Falmarri