Saturday 6 September 2008

PHP Fatal error: func_get_args(): Can't be used as a function parameter

Well, I was a little surprised about this message but then reading the documentation it all made sense.

The only way around this is to place the result of func_get_args() in a variable and then pass that variable to the function you were calling in the first place instead of func_get_args().

WON'T WORK:

my_func(func_get_args());


WILL WORK:

$func_args=func_get_args();
my_func($func_args);


This is because the func_get_args() function must get called in the right context to return the right values as explained in the PHP documentation (PHP.net func_get_args):

Note: Because this function depends on the current scope to determine parameter details, it cannot be used as a function parameter. If this value must be passed, the results should be assigned to a variable, and that variable should be passed.


Interesting.

Thoughts?

8 comments:

SlyK said...

Thanks for the info!
I was surprised too :)

Anonymous said...

Actually I was surprised too, but for the fact that it worked that way on my local server and threw this error on remote one.

Unknown said...

I had the same issue as anonymous. I put it down to the fact that my local environment was running PHP 5.3 and remote 5.2. I can't promise this is the reason, but seems most likely.

Unknown said...

thanks you. this solved my problem too. :)

Vipin Jose said...

thanksssssss

Oleg said...

Thanks from Russia:) I've been looking for, but a simple solution is found in this site only! Sorry for my english))

Rasim SEN said...

thank you my friend ;)

Anonymous said...

Thank you so much.... searched alot but dint find any answer.... Thanks again :)

Online Marketing
Add blog to our blog directory blog search directory Blog Directory Blogarama - The Blog Directory