I’m trying to create functions dynamically with eval(). But I get this warning: Notice: Use of undefined constant Any suggestion?
$funcs = array('func_a', 'func_b', 'func_c');
foreach($funcs as $func_name) {
eval( 'function ' . $func_name . '() {
mainfunc(' . $func_name . ');
}'
);
}
func_a();
func_b();
func_c();
function mainfunc($func_name) {
echo $func_name . '<br />';
}
Assuming the array $func is an option value stored in a database and I need the function names for a callback function in a separate part of the script. So creating anonymous functions with create_function() is not what I’m looking for.
Thanks for your info.
Your eval body needs to read:
Without the single quotes, eval() makes code that has an unquoted literal–an undefined constant.