Page 1 of 1

why use call_user_func()

Posted: Fri Nov 09, 2012 1:20 pm
by Live24x7
wondering why php provides call_user_func()

why would somebody use:

$returnVal = call_user_func("myFunction");

instead of :

$returnVal = myFunction();

any special cases where call_user_func() may be more useful ?

Re: why use call_user_func()

Posted: Fri Nov 09, 2012 3:27 pm
by Christopher
There are cases where you have the name of the function in a variable and need a way to call it instead of using $$functionname. Also there is a related function that allows to the pass the function parameters as an array which I have found handy on occasions.

Re: why use call_user_func()

Posted: Mon Feb 11, 2013 4:58 pm
by jraede
Also some methods require variables to be passed as a reference. You can get around that by creating an array with the referenced variables and then using call_user_func($method, $array_of_referenced_variables);

Re: why use call_user_func()

Posted: Thu May 16, 2013 6:42 am
by johngill2810
call_user_func is for calling functions whose name you don't know ahead of time but it is much less efficient since the program has to lookup the function at runtime.

Re: why use call_user_func()

Posted: Mon May 27, 2013 6:02 am
by annaharris
Check out given link to get background Image in HTML Mail. http://blog.mailermailer.com/email-desi ... aked-truth