| 1 | <?php |
||
| 4 | trait UuidTrait |
||
| 5 | { |
||
| 6 | /** |
||
| 7 | * @var string Primary key UUID |
||
| 8 | * |
||
| 9 | * @ORM\Id |
||
| 10 | * @ORM\Column(type="integer") |
||
| 11 | * @ORM\GeneratedValue(strategy="UUID") |
||
| 12 | */ |
||
| 13 | protected $id; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * Return primary key UUID identifier. |
||
| 17 | * |
||
| 18 | * @return string Primary key UUID |
||
| 19 | */ |
||
| 20 | public function getId() |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Sets primary key UUID identifier. |
||
| 27 | * |
||
| 28 | * @param string $id Primary key UUID |
||
| 29 | * |
||
| 30 | * @return UuidTrait |
||
|
|
|||
| 31 | */ |
||
| 32 | public function setId($id) |
||
| 38 | |||
| 39 | |||
| 40 | } |
||
| 41 |
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.