ErrorMessage.class.php 文件内容:
class ErrorMessage{
static $Error_none = 0;//API请求成功
public static $Error_validation = 1; //API请求验证失败
public static $Error_register = 2; //API请求注册失败
public static $Error_login = 3; //API请求登录失败
protected static $Error_protected = -1;//外部不可访问
private static $Error_private = -2;//外部不可访问
public static function getErrorMessage( $code = 0 )
{
$Error_Message = array(
self::$Error_none=> "结果正确",
self::$Error_validation=> "验证失败",
static::$Error_register=> "注册失败",
ErrorMessage::$Error_login=> "登录失败",
ErrorMessage::$Error_protected=> "Error_protected",
ErrorMessage::$Error_private=> "Error_private",
);
return $Error_Message[$code];
}
}
调用示例:
echo"\$Error_none : "; echo ErrorMessage::getErrorMessage(0);echo"<hr/>";
echo"\$Error_validation : "; echo ErrorMessage::getErrorMessage(1);echo"<hr/>";
echo"\$Error_register : "; echo ErrorMessage::getErrorMessage(2);echo"<hr/>";
echo"\$Error_login : "; echo ErrorMessage::getErrorMessage(3);echo"<hr/>";
实例化对象调用示例:
$error=new ErrorMessage();
echo"\$Error_none :"; print_R($error->getErrorMessage(0));echo"<hr/>";
echo"\$Error_validation :"; print_R($error->getErrorMessage(1));echo"<hr/>";
echo"\$Error_register :"; print_R($error->getErrorMessage(2));echo"<hr/>";
echo"\$Error_login :"; print_R($error->getErrorMessage(3));echo"<hr/>";
Paste_Image.png
继承父类:
class Err extends ErrorMessage{
public static $Error_protecteds = -1;
public static $Error_privates = -2;
static public function getErr($code = 0){
return parent::getErrorMessage($code);
}
}
调用示例:
//echo Err::$Error_protected;echo"<hr/>";//调用父类受保护属性会报错
//echo Err::$Error_private;echo"<hr/>"; //调用父类私有属性会报错
echo Err::$Error_protecteds;echo"<hr/>";
echo Err::$Error_privates;echo"<hr/>";
echo Err::getErr(0);echo"<hr/>";
echo Err::getErr(1);echo"<hr/>";
echo Err::getErr(2);echo"<hr/>";
echo Err::getErr(3);echo"<hr/>";
echo Err::getErr(-1);echo"<hr/>";
echo Err::getErr(-2);echo"<hr/>";
Paste_Image.png
网友评论