如何在PHP中自动加载函数

I use this code to load classes

 function __autoload($className)
 {
      $files = dirname(__FILE__).'/public/class/'.$className.'.php';

      if(file_exists($files))
      {
           include_once($files);
      }
 }

does anyone know how to retrieve the function automatically, too? Thank you.

Autoloader function registered spl_autoload_register() can be used to load classes, but not functions. Wrap your functions in class or classes to utilize autoloading, i.e.

class Utils {
  static function foo() {
    ..
  }
}

then call it static way:

Utils::foo();

and you can have it autoloaded when needed. See more infromation on autoloading in PHP manual.

Yes, you can automatically load classes using the autoload feature, but no, you can't do the same for functions.