In
php, we often use theerror_reportingfunctionwhen handling errors. The
error_reporting() function tells you what kind of PHP errors should be reported. Thisfunction enables setting the error_reporting directive at runtime.
PHP has many error levels. Use this function to set the level when the script is running. If the optional parameter level is not set, error_reporting() will only return the currenterror reportinglevel.
The one you can see most is error_reporting(E_ALL ^ E_NOTICE). What does this mean? Let me take a look.
First of all, you must know that the error_reporting() function is used to set the error level and return the current level. It has 14 error levels, as follows:
1 E_ERROR 致命的运行时错误。 错误无法恢复过来。脚本的执行被暂停 2 E_WARNING 非致命的运行时错误。 脚本的执行不会停止 4 E_PARSE 编译时解析错误。解析错误应该只由分析器生成 8 E_NOTICE 运行时间的通知。 16 E_CORE_ERROR 在PHP启动时的致命错误。这就好比一个在PHP核心的E_ERROR 32 E_CORE_WARNING 在PHP启动时的非致命的错误。这就好比一个在PHP核心E_WARNING警告 64 E_COMPILE_ERROR 致命的编译时错误。 这就像由Zend脚本引擎生成了一个E_ERROR 128 E_COMPILE_WARNING 非致命的编译时错误,由Zend脚本引擎生成了一个E_WARNING警告 256 E_USER_ERROR 致命的用户生成的错误。 512 E_USER_WARNING 非致命的用户生成的警告。 1024 E_USER_NOTICE 用户生成的通知。 2048 E_STRICT 运行时间的通知。 4096 E_RECOVERABLE_ERROR 捕捉致命的错误。 8191 E_ALL来 所有的错误和警告。
It seems that php does not enable errors by default, so you need to configure the php.ini file:
Changedisplay_errors = Off changed to display_errors = On
Also configure the error level: Change
error_reporting = E_ALL to:
error_reporting = E_ALL & ~E_NOTICE
It should be that php displays all errors by default, and we do not need to display some harmless prompts, so the settings are as above!
Can also be used inphp codeas follows:
The above is the detailed content of Detailed explanation of the usage of php error_reporting() function. For more information, please follow other related articles on the PHP Chinese website!