What are differences between error_reporting(E_ALL) and error_reporting(E_ALL & ~E_NOTICE)

丶灬走出姿态 提交于 2019-12-30 06:31:14

问题


Could anyone explain differences between error_reporting(E_ALL); and error_reporting(E_ALL & ~E_NOTICE); ?

I noticed that when I change from E_ALL to E_ALL & ~E_NOTICE, an error which I was hacking, disappears.


回答1:


E_ALL is "everything"

E_ALL & ~E_NOTICE is "everything except notices"

Notices are the least-urgent kinds of messages. But they can be very useful for catching stupid programmer mistakes, like trying to read from a hash with a non-existent key, etc.

(To understand the syntax, read up on bitwise operators)




回答2:


E_ALL would should all the error and warning and notice - everything

E_NOTICE is a special error level, showing things that won't produce error but are not good or gonna be obsolete in future release of PHP. The notice error level is meant to encourage best practices.

Also it should be error_reporting(E_ALL ^ E_NOTICE); to report everything except notice.

You are advice during development to set the error reporting to E_ALL and fix all the notice errors.

a look in the manual would give much more details.




回答3:


E_ALL is a flag E_NOTICE is a flag as well

so when you do bitwise operation of ~ which is NOT you'll exclude E_NOTICE from E_ALL

Under the hood following happens

in decimal

E_ALL = 32767 
E_NOTICE = 8

they are power of 2

bitwise

E_ALL    = 111111111111111
E_NOTICE = 000000000001000

result of NOT will be

111111111110111

then php can internally check if notices are ON with &(AND) operator

111111111110111
000000000001000

1 & 0 = 0 it means it is turned off. If however you didn't use ~ NOT then it would be 1 & 1 = 1 it means that flag is SET

There are other options for example OR to turn on the flag, or XOR to change the flag to opposite state. Basically, this is how flags work.



来源:https://stackoverflow.com/questions/1678859/what-are-differences-between-error-reportinge-all-and-error-reportinge-all

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!