Silly question about dependency injection

Posted 4 years ago by itstrueimryan

What's the difference between this:

public function __construct(CommandTranslator $commandTranslator)
 $this->commandTranslator = $commandTranslator;

and doing something like this instead, like on a custom PHP project where no dependency injection class has been created:

public function __construct()
 $this->commandTranslator = new CommandTranslator;

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.