陷入oop代码

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

The object to which has this method is initalized using another object of type UserRepository[1]

public function __construct(UserRepository $userRepository){

It save for further use is parameter.

$this->repository = $userRepository;

The __construct[2] function is called whenever you use a new Object(), new Object($RepositoryObject) in your case, instruction to instanziate a class into a variable.

Said that, the constructor is a base of the oop paradigm, you should invest some of your time to learn some on it (or how php enforce the oop paradigm[3]) in order to code with proficiency

References:

[1]http://www.php.net/manual/en/language.oop5.typehinting.php
[2]http://www.php.net/manual/en/language.oop5.decon.php
[3]http://www.php.net/manual/en/language.oop5.php