I'm trying to get a handle on using OOP with PHP, and I'm a little stumped with some of the class inheritance stuff.
Here's a couple simple classes I'm using to try to learn the way these work. I want to simply set a variable in the calling (parent) class from a child class. From the examples I've read it seems like this should work, but the sub class fails to set the parent variable:
class test {
private $myvar;
private $temp;
function __construct(){
$this->myvar = 'yo!';
$temp = new test2();
$temp->tester();
echo $this->myvar;
}
public function setVar($in){
$this->myvar = $in;
}
}
class test2 extends test{
function __construct(){
}
public function tester(){
parent::setVar('yoyo!');
}
}
$inst = new test(); // expecting 'yoyo!' but returning 'yo!'
Thanks for any help.