自动包含缺少的功能? [英] Automatically include missing functions?
问题描述
可能重复:
php中的自动加载功能
我正在开发一个PHP框架。我想知道当一个函数不存在时,是否有办法重写错误处理程序,以自动尝试包含首先显示该函数的文件。
I am working on a PHP framework. I wonder if there is a way to maybe rewrite the error handler when a function doesn't exist to automatically try to include the file stating the function first.
示例: / p>
Example:
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.
从这个胜利将是跳过编译不必要的文件或跳过跟踪和状态包括在这里和
The win from this would be to skip compiling unnecessary files or to skip keeping track and state includes here and there.
简单的__autoload函数而不是类。
Simply __autoload for functions rather than classes.
推荐答案
它不存在,可能永远不会。是的,我也想要这样做...但是,这并不妨碍你使用带有静态函数的类,并让PHP自动加载。
It does not exists and probably will never. Yes, I would like it too... However, this does not prevent you from using classes with static functions and let PHP autoload.
http://php.net/spl-autoload-register
这篇关于自动包含缺少的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!