spl_autoload_register 实现类的自动加载

来源:互联网 发布:投资理财软件 编辑:程序博客网 时间:2024/06/05 20:39
include.php
<?php$include = array('test');set_include_path(get_include_path() . PATH_SEPARATOR .implode(PATH_SEPARATOR, $include));class Loader{    /**     * 自动加载类     * @param $class 类名     */    public static function autoload($class)    {        $path = '';        $path = $class. '.php';        @include_once($path);    }}/** * spl自动加载 */spl_autoload_register(array('Loader', 'autoload'));


使用时只需要include ‘include.php’;即可以