I found this code in a library. Can anyone please help me what this means?
public function __construct(UserRepository $userRepository){
$this->repository = $userRepository;
}
I found this code in a library. Can anyone please help me what this means?
public function __construct(UserRepository $userRepository){
$this->repository = $userRepository;
}
__construct is the constructor of its containing class - function that's going to get called when you instantiate (create a new object of the class).
(UserRepository $userRepository) the argument/parameter that must be sent to the constructor, in this case type hinting is used, which means the object you send to your constructor must be of type UserRepository or at least inherit from UserRepository.
Judging by the name of the variable passed to the constructor, I would guess you will want to read up a bit on the Repository Pattern.
Sources
http://www.php.net/manual/en/language.oop5.typehinting.php http://www.php.net/manual/en/language.oop5.decon.php