PHP子类的同名函数必须与父类的参数一致吗? 100
classModel{publicfunctionadd(array$data,array$table=[],$class='',$function=''){return...
class Model
{
public function add(array $data, array $table = [], $class = '', $function = '')
{
return $data['name'];
}
}
class User extends Model
{
protected $table = [];
public function add(array $data)
{
return parent::add($data, $this->table, __CLASS__, __FUNCTION__);
}
}
$class = new User();
echo $class->add(['name' => '张三'])
这样就出错了,必须把子类方法也定义成
public function add(array $data, array $table = [], $class = '', $function = '')
跟父类一样的参数才行,不想在子类也定义那么多冗余参数有方法吗,? 展开
{
public function add(array $data, array $table = [], $class = '', $function = '')
{
return $data['name'];
}
}
class User extends Model
{
protected $table = [];
public function add(array $data)
{
return parent::add($data, $this->table, __CLASS__, __FUNCTION__);
}
}
$class = new User();
echo $class->add(['name' => '张三'])
这样就出错了,必须把子类方法也定义成
public function add(array $data, array $table = [], $class = '', $function = '')
跟父类一样的参数才行,不想在子类也定义那么多冗余参数有方法吗,? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询