ConFoo Montreal 2026: Call for Papers

Voting

: one minus one?
(Example: nine)

The Note You're Voting On

Hirusha Sharma
4 years ago
Fetch properties from functions:

----------------------------------------
Function definition with attributes:
----------------------------------------
#[ReadOnly]
#[Property(type: 'function', name: 'Hello')]
function Hello()
{
return "Hello";
}

-----------------------------------------
Gather attributes from the function
-----------------------------------------
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));

-----------------------------
OUTPUT
-----------------------------
Array
(
[ReadOnly] => Array
(
)

[Property] => Array
(
[type] => function
[name] => Hello
)

)

<< Back to user notes page

To Top