本文整理汇总了PHP中ReflectionFunctionAbstract::getModifiers方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionFunctionAbstract::getModifiers方法的具体用法?PHP ReflectionFunctionAbstract::getModifiers怎么用?PHP ReflectionFunctionAbstract::getModifiers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionFunctionAbstract
的用法示例。
在下文中一共展示了ReflectionFunctionAbstract::getModifiers方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _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}";
}