| 1 | <?php |
||
| 18 | trait EnvironmentTrait |
||
| 19 | { |
||
| 20 | /** @var Environment */ |
||
| 21 | protected $environment; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Set application environment |
||
| 25 | * |
||
| 26 | * @param Environment $environment |
||
| 27 | * |
||
| 28 | * @return EnvironmentTrait |
||
|
|
|||
| 29 | */ |
||
| 30 | public function setEnvironment(Environment $environment) |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Get environment object |
||
| 39 | * |
||
| 40 | * @return Environment |
||
| 41 | */ |
||
| 42 | public function getEnvironment() |
||
| 46 | } |
||
| 47 |
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.