Referring to my above question. What is the consequence of 'new'ing a class or inject a class in Laravel Controller?
Ex:
public class ArticleController extends Controller
{
protected $articleRepo;
protected $userRepo;
protected $documentRepo;
public function __construct() {
$this->articleRepo = new ArticleRepo();
$this->userRepo = new UserRepo();
$this->documentRepo = new DocumentRepo();
}
}
public class ArticleController extends Controller
{
protected $articleRepo;
protected $userRepo;
protected $documentRepo;
public function __construct(ArticleRepo $articleRepo, UserRepo $userRepo, DocumentRepo $d ocumentRepo) {
$this->articleRepo = $articleRepo;
$this->userRepo = $userRepo;
$this->documentRepo = $documentRepo
}
}
I know Dependency injection is the best approach, but my question what is the consequence of 'new'ing them instead of injecting them? 'new'ing does it mean consumes memory?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community