可能重复:
php中的自动加载函数
我正在开发一个 PHP 框架。我想知道是否有一种方法可以在函数不存在时重写错误处理程序以自动尝试首先包含说明该函数的文件。
例子:
echo general_foo(); // <-- general_foo() is not yet stated.
// A handler tries to include_once('functions/general.php') based on the first word of the function name.
// If the function still doesn't exist - throw an error.
这样做的好处是跳过编译不必要的文件或跳过跟踪和状态包括在这里和那里。
只需 __autoload 用于函数而不是类。