利用php的set_error_handler()函数,在zf的引导类文件或初始化类文件中添加如下代码:
1 public function __construct($application) { 2 parent::__construct($application);3 3 MyApp_Error_Handler::set(); 4 }
定义MyApp_Error_Handle类
1 class MyApp_Error_Handler { 2 public static function handle($errno, $errstr, $errfile, $errline) 3 { 4 if (!error_reporting()) return; 5 throw new Exception($errstr . " in $errfile:$errline". $errno); 6 } 7 8 public static function set() 9 { 10 set_error_handler(array(__CLASS__, 'handle')); 11 } 12 }