php版本5.4.12
php strict standards: declaration of db_attach::needby() should be compatible with spmodel::needby($id, $value) in c:\php\web\db\db_attach.php on line 25
重写的时候参数不一致,看了网上的方法
1.给重写的函数参数初始化
2.设置error_reporting为error_reporting(e_all & ~(e_strict | e_notice))(我是在php.ini添加的)
总是无法屏蔽这个错误。请问有什么办法吗?谢谢
回复讨论(解决方案) 再加一个 & ~e_deprecated
通常此类错误时不该屏蔽的
按着提示修改一下,可以使程序更健壮
还是不行啊,重写不是不要求参数一致吗?这个要改,程序动的太多了,难道要换版本?
贴出你的代码,只贴相关的部分
这样空对空的说不清楚
class access{
public function needby($field, $value)
{
return $this->find(array($field=>$value));
}
}
class dbconect extends access
{
function needby($id)
{
return $this->find(array('id'=>$id),'','uid,path');
}
}
谢谢,帮忙看看,还需要什么随时提供
等不急了!
测试了一下 class c { function test( $a ) { return 1; } } class cc extends c { function test() { return null; } } $cc = new cc();
strict standards: declaration of cc::test() should be compatible with c::test($a) in ...
这很简单,重写方法的函数签名本应该就和基类函数是一致的,这也是符合自然规律的,因为override本来就是覆盖的意思嘛,既然覆盖了,那么就应该和原函数一致,不然怎么能“盖”的住呢
呵呵,贴的比我写还快
access::needby($field, $value) 有两个参数
dbconect 继承于 access
dbconect::needby($id) 只有一个参数,所以出错。原因上面已说
只需
dbconect::needby($id, $null=null) 加一个可缺省的参数
就可以了
这段写的,我觉得是版本问题
reproduce code:
---------------
expected result:
----------------
none of the code blocks should trigger an error (my personal preference) or both code blocks must trigger a notice.
actual result:
--------------
first block triggers:
strict standards: declaration of cc::test() should be compatible with that of c::test() in strict_test.php on line 4
second does nothing at all.
缺省的参数的方法不错,测试通过,谢谢版主,学习了,以后还要经常请教,非常感谢!
当然与版本有关啦
php 用的人太多了,所以开发者们有意的制造些障碍
到 php5.5 就可能象 java 一样严厉了
于是就成了解释执行的 java 永远跟在 java 后面吃屎