本文整理汇总了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, '\\');
}
}
示例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}";
}