P粉5365327812023-08-27 12:10:24
問題是,當我們呼叫 Types::A->value 時,它實際上創建了一個列舉的實例,它不是一個常數值。 為了解決這個問題,定義一個常數並引用它。
<?php abstract class Type { public const A = 'a'; public const B = 'b'; } enum TypesEnum:string { case A = Type::A; case B = Type::B; } #[Attribute(Attribute::TARGET_CLASS)] class MyAttribute { public function __construct(public readonly array $mapping) { } } #[MyAttribute(mapping: [Type::A => ''])] class Entity { }
注意這個php 中的問題