Problem with call_user_func and references

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Pulni4kiya
Forum Commoner
Posts: 35
Joined: Tue Apr 14, 2009 6:20 am

Problem with call_user_func and references

Post 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?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Problem with call_user_func and references

Post 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.
Pulni4kiya
Forum Commoner
Posts: 35
Joined: Tue Apr 14, 2009 6:20 am

Re: Problem with call_user_func and references

Post 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! :)
User avatar
php_east
Forum Contributor
Posts: 453
Joined: Sun Feb 22, 2009 1:31 pm
Location: Far Far East.

Re: Problem with call_user_func and references

Post 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.
Pulni4kiya
Forum Commoner
Posts: 35
Joined: Tue Apr 14, 2009 6:20 am

Re: Problem with call_user_func and references

Post 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.
}
}
Post Reply