Re: how to invoke ReflectionMethod and pass variable by reference as argument?
- From: "Rik Wasmus" <luiheidsgoeroe@xxxxxxxxxxx>
- Date: Sat, 31 May 2008 00:58:16 +0200
On Fri, 30 May 2008 23:57:20 +0200, rafal.m <rafal.m.malinowski@xxxxxxxxx> wrote:
On 30 Maj, 23:48, Egbert Teeselink <skreb...@xxxxxxxxx> wrote:> $rc = new ReflectionClass('K2');
> $rm = $rc->getMethod('increment');
> $rm->invoke($a ,$c);
Weird indeed.
Does it work when using call_user_func, or call_user_func_array maybe?
like call_user_func(array($a, 'increment'), $c) or something. it may
be the reflection lib. or i'm missing something.
both:
call_user_func(array($a, 'increment'), $c);
and
call_user_method('increment',$a,$c);
gave me the same outcome:
before: 10
after: 10
As the manual states:
call_user_func():
Note: Note that the parameters for call_user_func() are not passed by reference.
call_user_func_array():
Note: Referenced variables in param_arr are passed to the function by a reference, others are passed by a value. In other words, it does not depend on the function signature whether the parameter is passed by a value or by a reference.
call_user_func_array(array($a,'increment'),array(&$c));
I suspect they have deployed similar code under the hood as call_user_func(_array) in the implementation of the ReflectionMethod invoke()/invokeArgs(). Certainly annoying when the function signature should just be followed IMHO.
--
Rik Wasmus
....spamrun finished
.
- References:
- Prev by Date: Re: Creating a simple hitcounter for PHP web pages. (saves to files)
- Next by Date: Re: using fopen() in write mode is failing
- Previous by thread: Re: how to invoke ReflectionMethod and pass variable by reference as argument?
- Next by thread: Re: how to invoke ReflectionMethod and pass variable by reference as argument?
- Index(es):
Relevant Pages
|