<?php class MyAttributeBase {} class MyAttribute extends MyAttributeBase {} class C { public function __construct( #[\SensitiveParameter] #[MyAttribute] public string $x, ) {} } new C('hello'); $param = (new ReflectionMethod('C', '__construct'))->getParameters()[0]; spl_autoload_register(function (string $class) { $line = debug_backtrace()[1]['line']; print "Line $line: Trying to autoload $class.\n"; }); $attributes = $param->getAttributes(UnknownClass::class); assert($attributes === []); $attributes = $param->getAttributes(MyAttributeBase::class); assert($attributes === []); $attributes = $param->getAttributes(MyAttributeBase::class, \ReflectionAttribute::IS_INSTANCEOF); assert(count($attributes) === 1); assert($attributes[0]->getName() === MyAttribute::class); $attributes = $param->getAttributes(); assert(count($attributes) === 2); assert($attributes[0]->getName() === SensitiveParameter::class); assert($attributes[1]->getName() === MyAttribute::class); $attributes[0]->newInstance();
You have javascript disabled. You will not be able to edit any code.