-
Notifications
You must be signed in to change notification settings - Fork 8k
Closed as not planned
Description
Description
Would be nice if ReflectionAttribute::getArguments had an associative mode, for example
<?php
#[Attribute(Attribute::TARGET_PARAMETER)]
class ArgumentDescription {
public function __construct(
public string $description,
public mixed $example = null
) {}
}
function test(
#[ArgumentDescription("amount in USD", 9.99)]
float $amount,
) {}
$ref = new ReflectionFunction(test(...));
$parameter = $ref->getParameters()[0];
$parameterAttribute = $parameter->getAttributes()[0];
var_dump($parameterAttribute->getArguments());
var_dump($parameterAttribute->getArguments(associative: true));could print
array(2) {
[0]=>
string(13) "amount in USD"
[1]=>
float(9.99)
}
array(2) {
["description"]=>
string(13) "amount in USD"
["example"]=>
float(9.99)
}