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.
35 lines
724 B
35 lines
724 B
--TEST--
|
|
Symfony pattern: attribute named arguments with class constant values
|
|
--FILE--
|
|
<?php
|
|
|
|
#[Attribute(Attribute::TARGET_CLASS)]
|
|
class SymfonyLikeAlias
|
|
{
|
|
public function __construct(
|
|
public string $id,
|
|
public ?string $when = null,
|
|
) {
|
|
}
|
|
}
|
|
|
|
interface SymfonyLikeContract
|
|
{
|
|
}
|
|
|
|
#[SymfonyLikeAlias(id: SymfonyLikeContract::class, when: 'dev')]
|
|
class SymfonyLikeImplementation implements SymfonyLikeContract
|
|
{
|
|
}
|
|
|
|
function main(): void
|
|
{
|
|
$attribute = (new ReflectionClass(SymfonyLikeImplementation::class))->getAttributes(SymfonyLikeAlias::class)[0]->newInstance();
|
|
|
|
var_dump($attribute->id);
|
|
var_dump($attribute->when);
|
|
}
|
|
?>
|
|
--EXPECT--
|
|
string(19) "SymfonyLikeContract"
|
|
string(3) "dev"
|
|
|