I'm obviously not understanding inheritance correctly. I'll let my code do the talking:
abstract class Calc {
private $x;
private $y;
public function AddNumbers() {
echo $this->x. " + " .$this->y;
}
}
class myCalc extends Calc {
public function __construct ($x,$y) {
$this->x = $x;
$this->y = $y;
}
}
$calc1 = new myCalc(3,4);
$calc1->AddNumbers();
echo 'done';
exit;
OK, so what's going on here: I'd like to have an abstract class, that would define two properties (x and y) and an abstract method, (nevermind the concatenation of numbers, implementation of the method is out of the scope of my question) which would access there properties.
Then, a concrete class extends that abstract one. As you can see, I can successfully access the properties and set them, but when I call add numbers, it appears as if the properties are not set.
What is going on, why is this not working and how can I fix it? I could just define a method for adding numbers in concrete class, but I want to have a method in abstract class with a definition that can be reused.
Thanks!