I don't see any issue with this. If you have multiple classes that will all benefit from a parent class structured this way it makes it easy to add another method or another variable to all of the child classes at once in the future. I also checked to see how PHP handles inheritance since I was not 100% sure on this and also because php will automagically set variables for you if you assign to something like $this->doesnotexistyet = "magic!"; however the below outputs the following...
class A {
protected $d;
public function __construct() {
$this->d = "A";
}
public function getDP() {
return $this->d;
}
}
class B extends A {
public function __construct() {
$this->d = "B";
}
public function getD() {
return $this->d;
}
}
$a = new A();
echo $a->getDP() . PHP_EOL;
$b = new B();
echo $b->getD() . PHP_EOL;
echo $b->getDP() . PHP_EOL;
var_dump($a , $b);
Output.
A
B
B
object(A)#1 (1) {
["d":protected]=>
string(1) "A"
}
object(B)#2 (1) {
["d":protected]=>
string(1) "B"
}
This was more for me than anything but thought I would add it if it helps others who come across this.