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>