I need to pass a function as a parameter to another function and then call the passed function from within the function...This is probably easier for me to explain in code..I basically want to do something like this:
function ($functionToBeCalled) { call($functionToBeCalled,additional_params); }
Is there a way to do that.. I am using PHP 4.3.9
Thanks!
There is another type of function known as PHP Parameterized functions, these are the functions with pre defined parameters. You'll pass any number of parameters inside a function. These passed parameters act as variables in your function. They are declared inside the brackets, after the function name.
Just to add to the others, you can pass a function name: function someFunc($a) { echo $a; } function callFunc($name) { $name('funky! '); } callFunc('someFunc');
Definition and Usage. The is_callable() function checks whether the contents of a variable can be called as a function or not. This function returns true (1) if the variable is callable, otherwise it returns false/nothing.
I think you are looking for call_user_func
.
An example from the PHP Manual:
<?php function barber($type) { echo "You wanted a $type haircut, no problem"; } call_user_func('barber', "mushroom"); call_user_func('barber', "shave"); ?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With