so I\'m trying to work out an issue I\'m having in designing PHP classes. I\'ve created a base class, and assigned private variables. I have child classes extending this bas
Should be like this:
base.class.php:
class Base {
private $test;
public function __construct() {
echo $this->getTest();
}
public function getTest() {
return $this->test;
}
protected function setTest($value) {
$this->test = $value;
}
}
sub.class.php:
class Sub extends Base {
public function __construct() {
parent::setTest('hello!'); // Or, $this->setTest('hello!');
parent::__construct();
}
}
main code:
require 'base.class.php';
require 'sub.class.php';
$sub = new Sub; // Will print: hello!