Page 1 of 1

Problem with call_user_func and references

Posted: Tue Apr 14, 2009 8:17 pm
by Pulni4kiya
I need to call a method that returns reference using call_user_func or something like that. My problem is that call_user_func does not return a reference, neither does the ReflectionMethod::invokeArgs() method.

I'll most likely be able to do it with eval() but I was wondering if there is some other way?

Re: Problem with call_user_func and references

Posted: Tue Apr 14, 2009 9:12 pm
by Chris Corbyn
Unfortunately not. This is one of my gripes with PHP. func_get_args() does not return references neither. Very frustrating if you're working with by-reference methods.

Re: Problem with call_user_func and references

Posted: Tue Apr 14, 2009 9:28 pm
by Pulni4kiya
Yeah, I needed func_get_args with references, too.
It's very sad that PHP has these reference problems.
Guess, I'll do it with eval() then...not that I like it much...

Thanks anyway! :)

Re: Problem with call_user_func and references

Posted: Tue Apr 14, 2009 9:30 pm
by php_east
Pulni4kiya wrote:I need to call a method that returns reference using call_user_func or something like that.
could you provide me an example pls. i don't understand exactly what you mean. thanks.

Re: Problem with call_user_func and references

Posted: Tue Apr 14, 2009 9:32 pm
by Pulni4kiya
Something like this:

class A {
protected function &a($b1,$b2,$b3) { ... }
}

class B extends A {
protected function &a($b1,$b2,$b3) { ... }

public function &call($methodName, array $args) {
//I'm here and I want to call parent::$methodName($args); and return the reference it returned.
}
}