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

解决方案 »

  1.   

    再加一个 & ~E_DEPRECATED
      

  2.   

    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');
    }

    }谢谢,帮忙看看,还需要什么随时提供
      

  3.   

    等不急了!
    测试了一下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本来就是覆盖的意思嘛,既然覆盖了,那么就应该和原函数一致,不然怎么能“盖”的住呢
      

  4.   

    呵呵,贴的比我写还快access::needBy($field, $value) 有两个参数
    dbconect 继承于 access  
    dbconect::needBy($id) 只有一个参数,所以出错。原因上面已说
    只需
    dbconect::needBy($id, $null=null) 加一个可缺省的参数
    就可以了
      

  5.   

    这段写的,我觉得是版本问题Reproduce code:
    ---------------
    <?php
    // this code does trigger a strict message
    error_reporting( E_ALL | E_STRICT );class cc extends c {
      function test() { return null; }
    }class c {
      function test( $a ) { return 1; }
    }
    $cc = new cc();
    ?><?php
    // this code does NOT trigger a strict message
    error_reporting( E_ALL | E_STRICT );class c { 
      function test( $a ) { return 1; }
    }class cc extends c {
      function test() { return null; }
    }$cc = new cc();
    ?>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 4Second does nothing at all.
      

  6.   

    当然与版本有关啦
    php 用的人太多了,所以开发者们有意的制造些障碍
    到 php5.5 就可能象 java 一样严厉了
    于是就成了解释执行的 java —— 永远跟在 java 后面吃屎