How can we declare the function name dynamically?
For example :
$function = 'test'
public $function(){
}
How can we declare the function name dynamically?
For example :
$function = 'test'
public $function(){
}
You could use a callback for this:
https://stackoverflow.com/a/2523807/3887342
function doIt($callback) { $callback(); }
doIt(function() {
// this will be done
});
Declaring a function with a variable but arbitrary name like this is not possible without getting your hands dirty with eval() or include().
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+):
$variableA = function() {
// Do stuff
};
You can still call it as you would any variable function, like so:
$variableA();