ErrorTrait.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace common\traits;
  3. trait ErrorTrait
  4. {
  5. public $error = '';
  6. public $error_code = 0;
  7. public static $static_error = '';
  8. public static $static_error_code = 0;
  9. /**非静态调用储物处理 */
  10. public function setError($msg, $error_code = 0)
  11. {
  12. $this->error_code = $error_code;
  13. $this->error = $msg;
  14. }
  15. public function getError()
  16. {
  17. return $this->error;
  18. }
  19. public function getCodeError()
  20. {
  21. return array(
  22. 'code' => $this->error_code,
  23. 'error' => $this->error,
  24. );
  25. }
  26. /**静态调用错误处理 */
  27. public static function setStaticError($msg, $error_code = 0)
  28. {
  29. self::$static_error = $msg;
  30. self::$static_error_code = $error_code;
  31. }
  32. public static function getStaticError()
  33. {
  34. return self::$static_error;
  35. }
  36. public static function getStaticCodeError()
  37. {
  38. return array(
  39. 'code' => self::$static_error_code,
  40. 'error' => self::$static_error
  41. );
  42. }
  43. }