douwen7905
2013-05-01 19:50 阅读 38
已采纳

php调用error_reporting报告以前的严格通知

I have noticed that using php's error_reporting function at runtime seems to cause it to report notices that have occurred previously.

Is this by design, or is there a way to prevent it?

$er = error_reporting(E_ERROR);
$m = new MyClass();
$m->myFunction();
//error_reporting($er);  

In the above code, myFunction() calls 3rd-party code that raises warnings and/or "strict" notices. If the last line is commented out as it is above, those warnings and notices are not returned. However, if I uncomment that line so that error reporting can return to normal, the strict notices, but not the warnings, are reported at that point.

Update I think this is not a problem with error_reporting as I had originally thought, but instead an issue with Pear, the 3rd-party code I'm using.

See my post at php pear mail extension raises strict notices

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    douping1825 douping1825 2013-05-01 19:55

    I have noticed that using php's error_reporting function at runtime seems to cause it to report notices that have occurred previously.

    What you said is just regular behaviour at must related to parts of your code which you havn't posted. Check my example. It will call a non static method statically what will cause a E_STRICT message:

    Class A { 
        public function notStatic() {}
    }
    
    $a = new A();
    
    error_reporting(~E_ALL);
    $a::notStatic();   // ... silence
    
    error_reporting(E_ALL);
    $a::notStatic();   // Strict standards: Non-static method A::notStatic() should not be called statically in 
    
    点赞 评论 复制链接分享

相关推荐