1 | <?php |
||
7 | trait LicenceNumberTrait |
||
8 | { |
||
9 | /** |
||
10 | * @var string |
||
11 | */ |
||
12 | private $licence; |
||
13 | |||
14 | private function __construct(string $licence) |
||
18 | |||
19 | public function getLicence(): string{ |
||
22 | |||
23 | /** |
||
24 | * @return LicenceNumberTrait|static |
||
|
|||
25 | */ |
||
26 | public static function empty(): self{ |
||
29 | |||
30 | /** |
||
31 | * @param string $licence |
||
32 | * |
||
33 | * @return LicenceNumberTrait|static |
||
34 | */ |
||
35 | public static function create(string $licence): self{ |
||
38 | |||
39 | } |
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.