1 | <?php |
||
20 | trait ContainerAwareMethods |
||
21 | { |
||
22 | |||
23 | /** |
||
24 | * @var ContainerInterface |
||
25 | */ |
||
26 | protected $container; |
||
27 | |||
28 | /** |
||
29 | * Get container |
||
30 | * |
||
31 | * @return InteropContainer |
||
32 | */ |
||
33 | public function getContainer() |
||
37 | |||
38 | /** |
||
39 | * Set container |
||
40 | * |
||
41 | * @param InteropContainer $container |
||
42 | * |
||
43 | * @return self|$this|ContainerAwareMethods |
||
|
|||
44 | */ |
||
45 | public function setContainer(InteropContainer $container) |
||
50 | } |
||
51 |
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.