function foo($a,$b) {
require_once "funtions-foo.php";
return _foo($a,$b);
}
然而,这对我来说似乎有点重复。我要寻找的是一种方法,要么“捕获”一个函数调用,如果它的名称在一个“included”函数数组中,我将包含正确的文件并调用该函数。例如:
catch_function_call($function,$arg1,$arg2) {
$array = array(
'foo' => 'functions-foo.php',
'bar' => 'functions-bar.php'
);
if($array[$function]) {
require_once $array[$function];
return $function($arg1,$arg2);
}
}
$array = array(
'foo' => 'functions-foo.php',
'bar' => 'functions-bar.php'
);
foreach($array as $function => $file) {
function $function($arg1,$arg2) {
$_function = "_".$function;
require_once $file;
return $_function($arg1,$arg2);
}
}
当然,这给了我一个错误,因为在定义函数时,我显然不能在函数名中使用变量。有没有想过如何绕过这个或其他只在需要时包含函数的解决方案?