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 ?
why use call_user_func()
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: why use call_user_func()
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.
(#10850)
Re: why use call_user_func()
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);
-
johngill2810
- Forum Newbie
- Posts: 6
- Joined: Tue May 14, 2013 9:52 am
Re: why use call_user_func()
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.
-
annaharris
- Forum Commoner
- Posts: 30
- Joined: Mon Mar 25, 2013 6:52 am
Re: why use call_user_func()
Check out given link to get background Image in HTML Mail. http://blog.mailermailer.com/email-desi ... aked-truth