Answer the question
In order to leave comments, you need to log in
How to call an ancestor class variable?
There are two classes a and b how to get variables from class b if they are reassigned?
class a {
public $data;
}
class b extends a {
public $data;
public function get_data() {
Как вызвать $data класса a?
}
}
class a {
public $data;
}
class b extends a {
public $data;
public function get_data() {
parent::data;
}
}
class a {
public $data;
public function data() {
return $this->data;
}
}
class b extends a {
public $data;
public function get_data() {
parent::data();
}
}
Answer the question
In order to leave comments, you need to log in
you violated the basic principle of DRY (do not repeat yourself). this means that you don't need to define a variable with the same name and access in the child class if it exists in the parent(s)
parent::data;
Why are you calling like that? It's not a constant.parent::$data;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question