Thinkphp报错,详细见问题补充。但是好像不影响使用

错误信息:[2048] Declaration of IndexAction::show() should be compatible with that of
Action::show() I:\PHPnow\htdocs\ThinkPHP\Home\Lib\Action\IndexAction.class.php 第
10 行.

代码段:
<?php
class IndexAction extends Action {
public function show(){
$m=M('User');//实例化 new model()
$arr=$m->select();
$this->assign("data",$arr);
$this->display();
}
}

第1个回答  推荐于2017-11-26
代码段:
<?php
class IndexAction extends Action {
public function show(){
$m=M('User');//实例化 new model()
$arr=$m->select();
$this->assign("data",$arr);
$this->display();
}
}
如上面的代码:类Action中的show方法有参数,类IndexAction在继承Action后重写show方法时去除了参数,因此会产生一个类似下面E_STRICT级别的警告:
Strict standards: Declaration of ... should be compatible with that of ...
意思就是子类(IndexAction)重写的show方法与父类(Action)中的show方法不兼容,php方法重写要求是要参数个数、方法名称与父类要一致的,你要重写的话就要这样定义:
public function show($content,$charset='',$contentType='',$prefix=''){
//.....

}
不过不是错误,只是警告不影响运行。本回答被提问者采纳