I was watching an OOP lesson with such code:
class UsersConstroller {
protected $userService
protected $logger
public function __construct {
UserService $userService,
Logger $logger
}
}
What this class does is pass other class in the constructor, then it will assign them to variable, and they will be used with $this inside the class.
Is it wrong not to pass those classes in the constructor, and instantiate them directly where needed in the class code, like this:
( new Logger )->logMessage("this is a message")
This way, passing a lot of instances of other classes to the class would be avoided.