$this->format();
直接调用就行了啊,显然你没有理解继承中的重写
class ModelB
{
public function getList()
{
echo 'ModelB:getList';
$this->format();
}
public function format()
{
echo 'ModelB:format';
}
}
class ModelA extends ModelB
{
public function format()
{
echo 'ModelA:format';
}
}
(new ModelA)->getList();//ModelB:getList-ModelA:format-
<?php
class ModelB
{
public function getList()
{
$this->format();
}
public function format()
{
echo "I am ModelB".PHP_EOL;
}
}
class ModelA extends ModelB
{
public function format()
{
echo "I am ModelA".PHP_EOL;
}
}
class ControllerC
{
public $obj;
public function __construct()
{
$this->obj = new ModelA();
}
public function handle()
{
$this->obj->getList();
}
}
$obj = new ControllerC();
$obj->handle(); //输出"I am ModelA"