therefore, I am trying to solve a problem that occurs when developing PHP classes. I created a base class and assigned private variables. I have child classes extending this base class that reference and are modified by these private variables through the base class functions. Here is an example, keep in mind, I'm still confused by the difference between methods privateand protected/ variable (let me know if I do it wrong!):
base.class.php
<?php
class Base {
private $test;
public function __construct(){
require('sub.class.php');
$sub = new Sub;
echo($this->getTest());
}
public function getTest(){
return $this->test;
}
protected function setTest($value){
$this->test = $value;
}
}
?>
sub.class.php
<?php
class Sub extends Base {
public function __construct(){
parent::setTest('hello!');
}
}
?>
So, I expect the result to be hello!printed on the screen - there is nothing instead. Maybe a fundamental misunderstanding of the classes on my part, or maybe I'm just doing something wrong. Any guidance is greatly appreciated! Thank.
EDIT:
, - , , , - , , .