<?php

#[Attribute(Attribute::TARGET_FUNCTION)]
class F
{
}

#[Attribute(Attribute::TARGET_METHOD)]
class M
{
}

class C
{
    #[F]
    #[M]
    public function m()
    {
    }
}

#[F]
#[M]
function f() {}

function test(string $attributeClass, $value) {
    try {
        var_dump((new ReflectionFunction($value))->getAttributes($attributeClass)[0]->newInstance());
    } catch (Error $e) {
        echo $e->getMessage(), "\n";
    }
}

$m = [new C(), 'm'](...);
$f = f(...);

test(F::class, $f);
test(M::class, $f);
test(F::class, $m);
test(M::class, $m);

?>