View Full Version : func_get_args ... by reference?

01-20-2012, 04:23 PM
Consider the following code:

function myfunc($a, $b, $c)
$args =& func_get_args();

$args[0] = 1;

echo implode(", ", array($a, $b, $c)).PHP_EOL;

myfunc(2, 2, 3);

This outputs 2, 2, 3. Is there a built-function, akin to func_get_args, which returns an array of references to the function arguments, rather than copies? I can't find anything in the manual, but perhaps I'm looking in the wrong place!

01-20-2012, 05:05 PM
No, there is no way to pass by reference values created by func_get_args. You will need to specify them inside of the parameter list instead.

In PHP 5.x+ you can use objects which will use a object pointer to work with instead.

01-20-2012, 05:46 PM
How does the object point work? I have PHP 5.3.3.

EDIT: Oh, yes I understand. Ignore my question!