How can I get the value of variable defined in abstract class that is changed in instance of a class that extends it, through a function that was defined in abstract class? The following code should help to illustrate my problem:
Abstract class:
abstract class Kontroler {
private $pogled;
function __construct(){
}
public function pogled(){
return $this->pogled;
}
abstract function defolt();
}
Class that extends Kontroler:
class E404 extends Kontroler{
function __construct (){
}
function defolt(){
$this->pogled = 'aplikacija/viewsi/404/404.v.htm';
}
}
My problem is that I change the value of $pogled inside an instance of the E404 class, but when I call $instanceOfE404->pogled(); PHP returns value of null which is value of $pogled defined in abstract class. Why is this?
private in parent will remain private in the parent – child classes don’t see it. Create a getter function or make it protected.
See VisibilityDocs.