P粉5365327812023-08-27 12:10:24
The problem is that when we call Types::A->value, it actually creates an instance of the enum, which is not a constant value. To solve this problem, define a constant and reference it.
<?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 { }
Pay attention to this problem in php