<?php
#[Attribute]
class StrAttribute
{
public function __construct(public string $value)
{
}
}
#[Attribute]
class IntAttribute
{
public function __construct(public int $value)
{
}
}
#[StrAttribute('Class')]
#[IntAttribute(42)]
class Implementation
{
#[StrAttribute('Method')]
public function execute(): void
{
}
}
$reflectionClass = new ReflectionClass(Implementation::class);
foreach ($reflectionClass->getAttributes() as $attribute) {
echo $attribute->newInstance()->value . PHP_EOL;
}
$reflectionMethod = $reflectionClass->getMethod('execute');
foreach ($reflectionMethod->getAttributes() as $attribute) {
echo $attribute->newInstance()->value . PHP_EOL;
}