add(7, '不能找到文件:'.$file, __METHOD__, __LINE__); * 2、类中 * //定义为属性 * public $error = NULL; * //构造器中初始化error * $this->error = new base_error($this); * //使用 * ......(程序错误了) * $this->error->add(7, '不能找到文件:'.$file, __METHOD__, __LINE__); * 3、静态类中 * //定义为属性 * static public $error = NULL; * //在类定义外初始化属性 * base_db_connmgr: error = new base_error(base_db_connmgr); */ class base_error { public $ownerClass; public $errors; public function __construct($owner = NULL) { if (is_string($owner)) { $this->ownerClass = $owner; } else if (is_object($owner)) { $this->ownerClass = get_class($owner); } else { $this->ownerClass = 'NONE'; } } /** * 添加一个error * @param unknown_type $no 错误号(非零) * @param unknown_type $msg 错误信息(字符串、base_error对象) * @param unknown_type $method 如果在函数内调用,传入__METHOD__,否则传入NULL * @param unknown_type $line 行号,传入__LINE__ */ public function add($no, $msg = '', $method = NULL, $line = 0) { if ($this->errors == NULL) { $this->errors = array(); } if ($no instanceof base_error) { $this->errors[] = array( 'no' => $no, 'msg' => $msg, 'path' => $method.'::'.$line ); } else { $this->errors[] = array( 'no' => $no, 'msg' => $msg, 'path' => $method.'::'.$line ); } } /** * 检查是否有错误(即是否有程序错误并调用了add) */ public function hasError() { return $this->errors !== NULL; } public function getErrorStack() { return print_r($this->errors, true); } } ?>
Fatal error: Class 'base_error' not found in /data/www/cntvmail/class/factory/model.cls.php on line 13 |