Invalid code:
$functionName = 'sayThis';
function $functionName($string) {
echo $string;
}
Can I do anything like this?
Invalid code:
$functionName = 'sayThis';
function $functionName($string) {
echo $string;
}
Can I do anything like this?
call_user_func
and call_user_func_array
do something similar. Use sparingly and judiciously.
I don't recommend you do this, but if you insist, using eval is an option.
Be extremely careful tho. And keep it far far away from any user input!
<?php
$name = 'sayThis';
$code = <<<PHP
function $name(\$string) {
echo \$string;
}
PHP;
eval($code);
$name('This is NOT a good idea!');
?>