コード例 #1
0
ファイル: smile.php プロジェクト: ziyueit/smile
 /**
  * 获取类方法的反射对象,方法不存在的时候返回null
  * @param ReflectionClass|ReflectionFunction $reflection 类反射的对象
  * @param string $method 需要获取的方法名字
  * @param string|null $default 如果指定方法不存在,就获取默认的方法名字
  * @return ReflectionMethod|ReflectionFunction|null
  */
 public static function getMethod($reflection, $method, $default = null)
 {
     if ($reflection instanceof ReflectionFunctionAbstract) {
         //如果已经是一个方法或者函数的反射,直接返回
         return $reflection;
     }
     if ($default && !$reflection->hasMethod($method)) {
         $method = $default;
     }
     if ($reflection->hasMethod($method)) {
         return $reflection->getMethod($method);
     } else {
         return null;
     }
 }