从函数中获取属性
----------------------------------------
带有属性的函数定义
----------------------------------------
#[ReadOnly]
#[Property(type: 'function', name: 'Hello')]
function Hello()
{
return "Hello";
}
-----------------------------------------
从函数中收集属性
-----------------------------------------
function getAttributes(Reflector $reflection)
{
$attributes = $reflection->getAttributes();
$result = [];
foreach ($attributes as $attribute)
{
$result[$attribute->getName()] = $attribute->getArguments();
}
return $result;
}
$reflection = new ReflectionFunction("Hello");
print_r(getAttributes($reflection));
-----------------------------
输出
-----------------------------
数组
(
[ReadOnly] => 数组
(
)
[Property] => 数组
(
[type] => function
[name] => Hello
)
)