First, a little background. The company I work for uses a massive function / class library, which gets included on every single page. Thousands and thousands of lines of functions, 90% of which probably won't even be called on a page.
In an attempt to lighten the server load a little, I've been experimenting with smarter library setups. To this end, I've split the entire file into categorized library files (i.e. sql.functions.php, date.functions.php, and others.)
Unfortunately, including every single file on every page doesn't help at all, and selectively including files is nearly impossible and very error-prone.
What I'm looking for is a setup similar to PHP's ___autoload()
function, which automatically searches for specifically named files in case an unknown Class is initiated, in an attempt to find it.
<?php
function ___autoload($class_name) {
require_once($class_name.'.class.php');
}
?>
However, this function does not work on function calls, only classes.
Is there a way to instruct PHP, when calling an undefined function (i.e. html_insert_button();
), to automatically look for and include a named function library?
(In the above case, html_functions.php
would need to be loaded, since it shares the function's prefix)