Re: Variable-length args by reference
| From: | Stefan Neufeind | Date: | Tue, 17 Apr 2012 22:10:15 +0000 |
| Subject: | Re: Variable-length args by reference | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-60117@lists.php.net to get a copy of this message | ||
On 04/18/2012 12:02 AM, Stefan Neufeind wrote:
> Hi,
>
> the topic of variable argument-lists for functions in connection with
> getting the parameters by reference came up. This is currently not
> possible with func_get_args(), though a "hack" with debug_backtrace() is
> possible.
>
> How would you think about extending func_get_args() and func_get_arg()
> to allow for:
>
> $args = func_get_args(FUNC_GET_ARGS_BY_REFERENCE);
> $arg0 = func_get_arg (0, FUNC_GET_ARGS_BY_REFERENCE);
>
> (default would be FUNC_GET_ARGS_BY_COPY)
>
>
> Currently only the following "hack" works:
>
> function calc()
> {
> $d = debug_backtrace();
> $args = $d[0]['args'];
> $args[0] *= 2;
> $args[1] *= 2;
> }
>
> $a = 5;
> $b = 7;
> var_dump ($a, $b);
> calc(&$a, &$b);
> var_dump ($a, $b);
Hmm, that example also only works because of the call-time
pass-by-reference? *sigh*
Sorry, I forgot those ampersands in the call to calc(). Doesn't work
without.
I hope the idea is clear though. Any chance we might make this possible
through func_get_args()?
Regards,
Stefan