是否有可能在PHP中加载一个函数,比如从外部文件中加入一个类.我正在尝试为辅助函数创建一个加载器,以便我可以调用:
$registry->helper->load('external_helper_function_file');
Run Code Online (Sandbox Code Playgroud)
之后它应该能够像这样调用文件中的函数:
$registry->helper->function();
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助
抛开意见,这是一个很好的OOP设计.甚至可以使用当前版本的PHP,尽管不像PHP5.3那样干净.
class Helper {
/* ... */
function load($file) {
include_once($file);
}
function __call($functionName, $args) {
if(function_exists($functionName))
return call_user_func_array($functionName, $args);
}
}
Run Code Online (Sandbox Code Playgroud)