日期:2014-05-17  浏览次数:20345 次

求助:关于继承错误的问题
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添加的)

总是无法屏蔽这个错误。请问有什么办法吗?谢谢
php

------解决方案--------------------
等不急了!
测试了一下
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) 加一个可缺省的参数
就可以了