| 1 | <?php |
||
| 7 | trait UuidTrait |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var string Primary key UUID |
||
| 11 | * |
||
| 12 | * @ORM\Id |
||
| 13 | * @ORM\Column(type="string") |
||
| 14 | * @ORM\GeneratedValue(strategy="UUID") |
||
| 15 | */ |
||
| 16 | protected $id; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Return primary key UUID identifier. |
||
| 20 | * |
||
| 21 | * @return string Primary key UUID |
||
| 22 | */ |
||
| 23 | public function getId() |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Sets primary key UUID identifier. |
||
| 30 | * |
||
| 31 | * @param string $id Primary key UUID |
||
| 32 | * |
||
| 33 | * @return UuidTrait |
||
|
|
|||
| 34 | */ |
||
| 35 | public function setId($id) |
||
| 41 | } |
||
| 42 |
In PHP traits cannot be used for type-hinting as they do not define a well-defined structure. This is because any class that uses a trait can rename that trait’s methods.
If you would like to return an object that has a guaranteed set of methods, you could create a companion interface that lists these methods explicitly.