Home  >  Article  >  Backend Development  >  "用:方式调用一个非静态方法会导致一个E_STRICT级别的异常。"真的吗

"用:方式调用一个非静态方法会导致一个E_STRICT级别的异常。"真的吗

WBOY
WBOYOriginal
2016-06-13 13:34:21767browse

"用::方式调用一个非静态方法会导致一个E_STRICT级别的错误。"真的吗?


class mycls{
  
  function func()
  {
  echo "none static";
  }

}

mycls::func();

?>

这里没有静态方法也可以运行啊,没出错啊

------解决方案--------------------
前面加上 error_reporting(2048); 就看见错误了

还不看见的话, 再 ini_set('display_errors',true);
------解决方案--------------------
这是PHP一直遗留的一个问题。
你之所以没有看到错误提示,是因为你并没有把 E_STRICT 纳入报错的错误类别之中。
error_reporting(E_ALL | E_STRICT); 加到最前面去就知道了
------解决方案--------------------
Strict standards: Non-static method mycls::func() should not be called statically in

关闭错误显示是一种方法,还有其他方法也可以达到目的
比如运行的时候关闭显示器.
------解决方案--------------------
其实这个错本来就不应该报的

无论是否静态方法都应该可以用 :: 访问
否则 prean::medhod 中的 :: 不就出现二义性了?

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn