I have this code:
class A {
var $arr = array();
function __construct($para) {
echo 'Not called';
}
}
class B extends A {
function __construct() {
$arr[] = 'new Item';
}
}
And as B has its own constructor construct($para) of A never gets called.
Now I could call parent::__construct($para) but then class B would need to be aware of the parameters class A needs.
I would prefer this:
class A {
var $arr = array();
function __construct($para) {
echo 'Not called';
}
}
class B extends A {
function __construct() {
parent::__construct(); // With the parameters class B was created.
// Additional actions that do not need direct access to the parameters
$arr[] = 'new Item';
}
}
Would something like that work?
I don't like the fact, that all classes that extend class A would need to define a new constructor, once class A changes its parameters, where all I want them to do is call the constructor of class A like when class B does not overwrite it with an own __construct() method.