当前位置: 首页>>代码示例>>PHP>>正文


PHP ReflectionFunctionAbstract::getReturnType方法代码示例

本文整理汇总了PHP中ReflectionFunctionAbstract::getReturnType方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionFunctionAbstract::getReturnType方法的具体用法?PHP ReflectionFunctionAbstract::getReturnType怎么用?PHP ReflectionFunctionAbstract::getReturnType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ReflectionFunctionAbstract的用法示例。


在下文中一共展示了ReflectionFunctionAbstract::getReturnType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getReturnType

 /**
  * @return string|NULL
  */
 public static function getReturnType(\ReflectionFunctionAbstract $func)
 {
     if (PHP_VERSION_ID >= 70000 && $func->hasReturnType()) {
         $type = PHP_VERSION_ID >= 70100 ? $func->getReturnType()->getName() : (string) $func->getReturnType();
         return strtolower($type) === 'self' ? $func->getDeclaringClass()->getName() : $type;
     }
     $type = preg_replace('#[|\\s].*#', '', (string) self::parseAnnotation($func, 'return'));
     if ($type) {
         return $func instanceof \ReflectionMethod ? self::expandClassName($type, $func->getDeclaringClass()) : ltrim($type, '\\');
     }
 }
开发者ID:nette,项目名称:di,代码行数:14,代码来源:PhpReflection.php

示例2: _scanFunction

 /**
  * @param ReflectionFunctionAbstract $function
  * @return string
  */
 private function _scanFunction(ReflectionFunctionAbstract $function, $class_name = "")
 {
     $params = [];
     foreach ($function->getParameters() as $param) {
         /* @var ReflectionParameter $param */
         $type = "";
         $param_name = "\$" . $param->name;
         if ($param->getClass()) {
             $type = $param->getClass()->name;
         } elseif ($param->hasType()) {
             $type = $param->getType();
         } elseif ($param->isArray()) {
             $type = "Array";
         } elseif ($param->isCallable()) {
             $type = "Callable";
         }
         if ($param->isVariadic()) {
             $param_name = "..." . $param_name;
         }
         if ($type) {
             $param_name = $type . " " . $param_name;
         }
         if ($param->isOptional()) {
             $params[] = "[ " . $param_name . " ]";
         } else {
             $params[] = $param_name;
         }
     }
     if ($function->hasReturnType()) {
         $return = " : " . $function->getReturnType();
     } else {
         $return = "";
     }
     $declare = $function->name;
     if ($function instanceof ReflectionFunction) {
         $declare = "function {$function->name}";
     } elseif ($function instanceof ReflectionMethod) {
         $mods = implode(' ', Reflection::getModifierNames($function->getModifiers()));
         if ($function->class !== $class_name) {
             $declare = "  method {$mods} {$function->class}::{$function->name}";
         } else {
             $declare = "  method {$mods} {$function->name}";
         }
     }
     return "{$declare}(" . implode(", ", $params) . "){$return}";
 }
开发者ID:php-ion,项目名称:php-ion,代码行数:50,代码来源:ionizer.php


注:本文中的ReflectionFunctionAbstract::getReturnType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。