As seen in the example here
interface Engine {}
class V8 implements Engine {}
class Car {
private $engine;
public function __construct(Engine $engine) {
$this->engine = $engine;
}
}
$injector = new Auryn\Injector;
$injector->define('Car', ['engine' => 'V8']);
$car = $injector->make('Car');
In the line $injector->define('Car', ['engine' => 'V8']);
, engine
is literally based on the parameter variable name of Car
's constructor ($engine
).
There's no problem with that but what if someday, the author of Car
decided to change the parameter variable name of its constructor to something else (e.g., public function __construct(Engine $motor)
)? This would break the injector.
Is there a way to avoid this, perhaps define by position instead of literal parameter names?