Answer the question
In order to leave comments, you need to log in
If I inherit from the parent class, how will this method work?
public function current_user(): User{
if (is_null($this->current_user)){
/**@var User $record*/
$record = User::find()->where(['id'=>$this->user_id])->one();
if ($record){
$this->current_user = $record;
}else{
$this->current_user = new User;
}
}
return $this->current_user;
}
Answer the question
In order to leave comments, you need to log in
When inheriting, the child method replaces the parent one, you can refer to the parent implementation through parent. More details: https://www.php.net/manual/ru/language.oop5.inheri...
And in general, read the entire section on php.net for at least a basic understanding of how classes and OOP work in php. Will remove a lot of questions)
The question is: if I call this method in the child class, will it take #this from the parent class or will it consider this as the child class? (I do not override this method in the child class)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question