From: Daniel Kolbo on
Hello,

I've defined a __call() method inside a class. Within the __call()
method (after testing that the method exists and is callable I am using:

call_user_func_array(array($this,$method), $args);

However, this seems to be an infinite loop (and is crashing my test
apache server). How, could I still use the __call() method and avoid an
infinite loop of calling?

Thanks,
dK
`
From: Peter Lind on
On 9 May 2010 23:21, Daniel Kolbo <kolb0057(a)umn.edu> wrote:
> Hello,
>
> I've defined a __call() method inside a class.  Within the __call()
> method (after testing that the method exists and is callable I am using:
>
> call_user_func_array(array($this,$method), $args);
>
> However, this seems to be an infinite loop (and is crashing my test
> apache server).  How, could I still use the __call() method and avoid an
> infinite loop of calling?

Assuming that your __call() method was reached because no $method was
defined, using call_user_func_array() to call $method on the same
object is going to result in ... your __call() method getting called
again. You need to map the $method to whichever class methods you
*actually* want to call, instead of blindly trying to reissue the
call.

Regards
Peter


--
<hype>
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51
</hype>
From: Nathan Nobbe on
On Sun, May 9, 2010 at 3:25 PM, Peter Lind <peter.e.lind(a)gmail.com> wrote:

> On 9 May 2010 23:21, Daniel Kolbo <kolb0057(a)umn.edu> wrote:
> > Hello,
> >
> > I've defined a __call() method inside a class. Within the __call()
> > method (after testing that the method exists and is callable I am using:
> >
> > call_user_func_array(array($this,$method), $args);
> >
> > However, this seems to be an infinite loop (and is crashing my test
> > apache server). How, could I still use the __call() method and avoid an
> > infinite loop of calling?
>
> Assuming that your __call() method was reached because no $method was
> defined, using call_user_func_array() to call $method on the same
> object is going to result in ... your __call() method getting called
> again. You need to map the $method to whichever class methods you
> *actually* want to call, instead of blindly trying to reissue the
> call.
>

according to op it sounds like hes not blindly reissuing the call,

(after testing that the method exists and is callable I am using:

anyways, Daniel, your code seems sound, hard to say where the recursion is
coming from. why not just dump the methods youre trying to invoke via
var_dump() or error_log() etc?

eg
...
var_dump($method);
call_user_func_array(array($this,$method), $args);


-nathan
From: Peter Lind on
On 9 May 2010 23:56, Nathan Nobbe <quickshiftin(a)gmail.com> wrote:
> On Sun, May 9, 2010 at 3:25 PM, Peter Lind <peter.e.lind(a)gmail.com> wrote:
>>
>> On 9 May 2010 23:21, Daniel Kolbo <kolb0057(a)umn.edu> wrote:
>> > Hello,
>> >
>> > I've defined a __call() method inside a class.  Within the __call()
>> > method (after testing that the method exists and is callable I am using:
>> >
>> > call_user_func_array(array($this,$method), $args);
>> >
>> > However, this seems to be an infinite loop (and is crashing my test
>> > apache server).  How, could I still use the __call() method and avoid an
>> > infinite loop of calling?
>>
>> Assuming that your __call() method was reached because no $method was
>> defined, using call_user_func_array() to call $method on the same
>> object is going to result in ... your __call() method getting called
>> again. You need to map the $method to whichever class methods you
>> *actually* want to call, instead of blindly trying to reissue the
>> call.
>
> according to op it sounds like hes not blindly reissuing the call,
> (after testing that the method exists and is callable I am using:

Good point that, misread. Would be good to see the code checking
availability of the method, to get some idea of the error.

Regards
Peter

--
<hype>
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51
</hype>
From: Richard Quadling on
On 9 May 2010 22:21, Daniel Kolbo <kolb0057(a)umn.edu> wrote:
> Hello,
>
> I've defined a __call() method inside a class.  Within the __call()
> method (after testing that the method exists and is callable I am using:
>
> call_user_func_array(array($this,$method), $args);
>
> However, this seems to be an infinite loop (and is crashing my test
> apache server).  How, could I still use the __call() method and avoid an
> infinite loop of calling?
>
> Thanks,
> dK

__call() is receiving $method.

Do you alter $method in any way?

If not, calling call_user_func(array($this, $method), $args) will
simply call the non-existent function.




--
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling