Possible Duplicate:
Use a variable to define a PHP function
Is there a way of using a variable as a function name.
For example i have a variable
$varibaleA;
and I want to create a function i.e.
function $variableA() {
}
so this function can be called later in the script. Does anyone know if this can be done?
Thanks
Declaring a function with a variable but arbitrary name like this is not possible without getting your hands dirty with
eval()orinclude().I think based on what you’re trying to do, you’ll want to store an anonymous function in that variable instead (use
create_function()if you’re not on PHP 5.3+):You can still call it as you would any variable function, like so: