相关疑难解决方法(0)

在SPL自动装载机中抛出异常?

有没有办法从PHP中的SPL自动加载器中抛出异常,以防它失败?它似乎不适用于PHP 5.2.11.

class SPLAutoLoader{

    public static function autoloadDomain($className) {
        if(file_exists('test/'.$className.'.class.php')){
            require_once('test/'.$className.'.class.php');
            return true;
        }       

        throw new Exception('File not found');
    }

} //end class

//start
spl_autoload_register( array('SPLAutoLoader', 'autoloadDomain') );

try{
    $domain = new foobarDomain();
}catch(Exception $c){
    echo 'File not found';
}
Run Code Online (Sandbox Code Playgroud)

当调用上面的代码时,没有异常的迹象,而是我得到一个标准的"致命错误:类'foobarDomain'在bla中找不到".并且脚本的执行终止.

php spl

5
推荐指数
1
解决办法
5644
查看次数

标签 统计

php ×1

spl ×1