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.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.