Accept my apologies for being beginner for OOP, according to the below code :
Class Test{
private $name = "youhana";
function setPrivatePropFromInside(){
$this->name = "mina";
}
function getPrivate(){
var_dump(__CLASS__);
echo $this->name ;
}
}
Class Test2 extends Test {
}
$obj2 = new Test2();
$obj2->getPrivate();
My Question is that Is Inheritance means to copy from parent to child or the child gain access to the parent visible members?
let me describe why I have confusion by mentioning my thoughts with both of the question members :
- In case its a copy, so the invoking the method getPrivate from the child object must return null because the private members will not be copied from the parent to the child, and also the CLASS constant must return Test2 not TEST in case the Inheritance means copying.
so the code mentioned above would equals :
Class Test{
private $name = "youhana";
function getPrivate(){
var_dump(__CLASS__);
echo $this->name ;
}
}
Class Test2 extends Test {
function getPrivate(){
var_dump(__CLASS__);
echo $this->name ;
}
}
- In case Inheritance means to gain access to the parent visible members, that doesn't refer or point to the concept of inheritance (the children get the characteristics of the parent) despite this concept is logically correct with the results upon executing the mentioned code snippet.
I Read more than 20 References and I still have the confusion, and again accept my apologies for being beginner searching for the correct approach.
Note that: I asked a question Here but after studying more references, I have been returned back to the confusion again, so I need a solid answer.