You can refer to the parent class to any methods defined in the heirs. Below Base::printProperty()
refers to the property()
method, which we override in the heirs. Moreover, we can demand that the heirs define property()
declaring it in the base class to be abstract (although this is not at all necessary).
abstract class Base { public function printProperty() { echo $this->property(); } abstract function property(); } class Child1 extends Base { public function property() { return 'Child1'; } } class Child2 extends Base { public function property() { return 'Child2'; } } $obj1 = new Child1(); echo $obj1->printProperty(); // Child1 $obj2 = new Child2(); echo $obj2->printProperty(); // Child2
The same is done in ActiveRecord, only the tableName()
method is not abstract, but implements the default logic.
class ActiveRecord extends BaseActiveRecord { ... public static function tableName() { return '{{%' . Inflector::camel2id( StringHelper::basename(get_called_class()), '_') . '}}'; } ... }