I have two questions related to OOP Inheritance object :
The first one is that according to the below code:
class Test { private $name = "Youhana"; function getPrivate(){ echo $this->name ; } } Class Test2 extends Test { } $obj2 = new Test2(); $obj2->getPrivate();
The result will be => Youhana, but how does this work, despite the inheritance means that members are cloned from the parent to child, so if this is correct, the code in the child class must be like the below logic:
Class Test2 {// simple imagination to the Test2 after extends Test CLass
function getPrivate(){ //which must return null not the value of the private member.
echo $this->name ;
}
}
Ref : Manual
Second question is that consider the below code:
Class Ex1{ function checkClassName(){ var_dump(__CLASS__); } } Class Ex2 extends Ex1{ } $obj2 = new Ex2(); $obj2->checkClassName();//how this will return EX1 although we invoked this function from the second object which after the inheritance will have a clone of public and protected members of the parent class?
How this will return EX1 although we invoked this function from the second object which after the inheritance will have a clone of public and protected members of the parent class?