| 1 | <?php |
||
| 7 | trait ProductTrait |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var boolean |
||
| 11 | * |
||
| 12 | * @ORM\Column(type="boolean") |
||
| 13 | */ |
||
| 14 | protected $validBarCode = false; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @return bool |
||
| 18 | */ |
||
| 19 | public function isValidBarCode(): bool |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @param bool $validBarCode |
||
| 26 | * @return ProductTrait |
||
|
|
|||
| 27 | */ |
||
| 28 | public function setValidBarCode(bool $validBarCode) |
||
| 33 | } |
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.