I understand why PHP
gives out this warning. What I don't understand, is why is this warning useful for anyone?
I mean, I find it completely valid, that an extended class, given that it can have new functionalities, could extend a function with new parameters, that are irrelevant in the extendees case.
Why is PHP
trying to enforce(or guide, because in reality, this is just a warning, not an error) us, to define extended functions with exactly the same number and/or type of parameters?
Let's take a concrete example:
class DatabaseTable {
protected $TableName; // stores the table name
protected $PrimaryKey; // stores the primary key column of this table
protected $PrimaryKeyValue; // stores the exact primary key for the table row this instance points to
protected $Structure; // stores the columns of this table, but in case of self, it is empty, as this would only be a template
public function update() {
// update the table row this instance points to, with anything that is in the structure
}
}
class ConcreteTable extends DatabaseTable {
protected $TableName = 'ConcreteTable';
protected $PrimaryKey = 'ConcreteTablePrimaryKey';
protected $Structure = array(
'Column1' => 'data-in-column-1',
'Column2' => 'data-in-column-2'
);
/** In this table, I am well aware that two columns exist, Column1, and Column2 **/
public function update(bool $skipColumn1, bool $skipColumn2) {
// revert skipped columns to their original value
parent::update();
}