ConstTraits.php 1012 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. /**
  3. * ----------------------------------------------------------------------------
  4. * 行到水穷处,坐看云起时
  5. * 开发软件,找贵阳云起信息科技,官网地址:https://www.56q7.com/
  6. * ----------------------------------------------------------------------------
  7. * Author: 老成
  8. * email:85556713@qq.com
  9. */
  10. declare(strict_types=1);
  11. namespace app\common\model\base;
  12. trait ConstTraits
  13. {
  14. public static function __callStatic($method, $args) {
  15. $classname=get_called_class();
  16. //判断当前类是否存在静态方法
  17. $class=new \ReflectionClass($classname);
  18. if($class->hasConstant($method)){
  19. //获取类的常量,常量名为$method
  20. $arr=constant("{$classname}::{$method}");
  21. foreach ($arr as $k=>$v){
  22. if($args[0]==$v){
  23. return $k;
  24. }
  25. }
  26. return null;
  27. }else{
  28. return parent::__callStatic($method, $args);
  29. }
  30. }
  31. }