1.2.345. Dependency Injection¶
A dependency injection is a typehinted argument, that is stored in a property by the constructor.
<?php
// Classic dependency injection
class foo {
private $bar;
public function __construct(Bar $bar) {
$this->bar = $bar;
}
public function doSomething($args) {
return $this->bar->barbar($args);
}
}
// Without typehint, this is not a dependency injection
class foo {
private $bar;
public function __construct($bar) {
$this->bar = $bar;
}
}
?>
See also Understanding Dependency Injection.
1.2.345.1. Connex PHP features¶
1.2.345.1.1. Specs¶
Short name |
Patterns/DependencyInjection |
Rulesets |
|
Exakat since |
0.11.6 |
PHP Version |
All |
Severity |
|
Time To Fix |
|
Precision |
Very high |
Available in |