Possible Duplicate:
autoload functions in 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.
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.
Simply __autoload for functions rather than classes.
I solved it like this
The class file classes/functions.php:
The function file functions/test.php
The script myscript.php:
You could eventually autoload classes/functions.php by using __autoload().
In the end, the syntax for my_function() becomes instead $functions->my_function(). And you can write your own error handlers if functions doesn't exist. ;)
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