Answer the question
In order to leave comments, you need to log in
Do I need to declare a property in a descendant?
The question may be quite stupid, but still. Tell. In this example, is it necessary to declare a property on the heir?
class Company{
protected $company_id = NULL;
//обязательно нужно указать ID организации
public function setCompany($id){
$this->company_id = $id;
}
public function getInfo(){
return $this->company_id;
//... return data array company...
}
}
class Department extends Company{
protected $company_id = NULL; //вот тут нужно?
public function test(){
return $this->getInfo();
}
}
//$a1 = new Company();
//$a1->setCompany(100);
$a2 = new Department();
$a2->setCompany(200);
echo $a2->test();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question