Call by reference to function arguments
| From: | Alain Williams | Date: | Mon, 07 Jul 2003 16:36:26 +0000 |
| Subject: | Call by reference to function arguments | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-154203@lists.php.net to get a copy of this message | ||
Hi,
I want to write a function (as I have written in several other languages) that
obtains it's arguments dynamically (using func_get_arg()) and then assigns to that
argument. Think of the way that scanf() works -- that sort of thing.
I have distilled what I want to do in the code below. foo adds 1 to all of it's arguments.
function foo () {
$count = func_num_args();
for($i = 0; $i <= $count; $i++) {
$var = func_get_arg($i);
// The following line should do it, but throws a syntax error
&$var = $var + 1;
}
}
$a = '1';
$b = '2';
$c = '3';
foo($a, $b, $c);
What I am doing is quite different than the above (and more complex), but I will be able
to achieve what I want if I can get the above to work.
--
Alain Williams
#include <std_disclaimer.h>