1.类的自动加载
如果调用某个不存在的类,报错前还有一次介入集合__autoload函数
系统会调用__autoload()函数并把 类名 自动传给__autoload函数
要用 spl_autoload_register通知系统,让系统知道自己写了一个自动加载的方法
2.异常处理(显示异常):throw-->try--->catch
Error_reporting(0);
class mysql{
protected $conn=null;
public function __construct(){
$this->conn=mysql_connect('localhost','root','');
//
if(!$this->conn)
{//错误原因,错误代码
$e=new Exception('漏油了',9);
throw $e;//扔出、抛出
}
}
}
try{//捕捉错误信息
$mysql=new mysql();
}catch(Exception $e){
echo '捕捉到错误信息';
echo $e->getMessage(),'<br/>';
echo '错误代码',$e->getCode(),'<br/>';
echo '错误文件',$e->getFile(),'<br/>';
echo '错误行',$e->getLine(),'<br/>';
}