i have a class
Paybox
This class is declare as a service.
In my controller class, i inject this service like this :
public function __construct($payboxService) {
$this->paybox = $payboxService;
}
public static function create(ContainerInterface $container) {
return new static(
$container->get('paybox_services'),
);
}
This declaration work fine, but i see sometime this in the constructor :
public function __construct(Paybox $payboxService) {
$this->paybox = $payboxService;
}
public static function create(ContainerInterface $container) {
return new static(
$container->get('paybox_services'),
);
}
They add the Type Paybox before $payboxService.
The 2 method work.
Can someone explain me the difference ? and what is the right way for inject the service ?
__construct($payboxService)
and__construct(Paybox $payboxService)
is plain PHP. Drupal doesn't change PHP syntax. – kiamlaluno♦ Aug 3 '17 at 11:52