TypePHP 编译器 https://swoole.com/aot/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

36 lines
601 B

--TEST--
Symfony pattern: nullsafe attribute newInstance chain
--FILE--
<?php
#[Attribute(Attribute::TARGET_CLASS)]
class TaggedItem
{
public function __construct(public int $priority = 0)
{
}
}
#[TaggedItem(priority: 20)]
class TaggedService
{
}
class UntaggedService
{
}
function priorityOf(string $class): ?int
{
return ((new ReflectionClass($class))->getAttributes(TaggedItem::class)[0] ?? null)?->newInstance()->priority;
}
function main(): void
{
var_dump(priorityOf(TaggedService::class));
var_dump(priorityOf(UntaggedService::class));
}
?>
--EXPECT--
int(20)
NULL