When a class extends another parent class
he can only use public and protected variables and functions
from the parent class..
So, you are right. private means private!
If we run this case, the displayed result will be: 1
... and with 2 notices:
Undefined property: theshow::$myVar2
Undefined property: theshow::$myVar3
But the new class also will have access to a public function output()
and by using this function he can access those private variables.
If we run $var->output, the displayed result will be: 6
<?php
class myClass {
protected $myVar1 = 1;
private $myVar2 = 2;
private $myVar3 = 3;
public function output() {
print ($this->myVar1+$this->myVar2+$this->myVar3);
}
}
class theshow extends myClass {
public function show() {
print ($this->myVar1+$this->myVar2+$this->myVar3);
}
}
$var = new theshow();
$var->show(); // result: 1
$var->output(); // result: 6
?>