從函式擷取屬性
----------------------------------------
具有屬性的函式定義
----------------------------------------
#[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
)
)