faqts : Computers : Programming : Languages : PHP : kms : Functions

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

7 of 14 people (50%) answered Yes
Recently 5 of 10 people (50%) answered Yes

Entry

How do you pass a function name as an argument to another function and then call the passed function? This would be similar to a function pointer in C

May 13th, 2000 05:15
Scott Weese,


You can do it by passing a string value that is the functions
name to the desired caller function but you have to make sure the
function to be called is defined before the desired caller is, that 
is, if you are using PHP3... You don't have to worry about what order
the functions were declared in PHP4. Heres an example:
function destination ($caller)
 {
  echo "Destination reached from origin: $caller<br>\n";
 }
function caller1 ($funcname)
 {
  $funcname("caller1");
 }
destination("main program");
caller1 ("destination");
This should output the following:
Destination reached from origin: main program<br>
Destination reached from origin: caller1<br>