Home > Article > Backend Development > About errors encountered in PHP development
In the process of program development and debugging errors, we will always encounter various errors. Some errors will affect the execution of the code, and some will just give a WARNING or NOTICE and will not affect the continuation of the following code. implement.
PHP provides an error control operator @. When it is placed before a PHP expression, any error information that may be generated by the expression is ignored. If you want to control the type of error output, you can use the error_reporting() function to tell the compiler what kind of error should be reported.
int error_reporting ([ int $level ] ): Set what kind of PHP errors should be reported
$level is the error level, return the old [error_reporting] level, or the level parameter is not given Returns the current level.
<?php // 关闭所有PHP错误报告 error_reporting(0); // Report simple running errors error_reporting(E_ERROR | E_WARNING | E_PARSE); // 报告 E_NOTICE也挺好 (报告未初始化的变量或者捕获变量名的错误拼写) error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE); // 除了 E_NOTICE,报告其他所有错误 error_reporting(E_ALL ^ E_NOTICE); // 报告所有 PHP 错误 (参见 changelog) error_reporting(E_ALL); // 报告所有 PHP 错误 error_reporting(-1); // 和 error_reporting(E_ALL); 一样 ini_set('error_reporting', E_ALL); ?>
The error levels and constants are defined in PHP's predefined constants:
The ones we often encounter in development are E_ERROR, E_WARNING, E_PARSE,E_NOTICE.
For more PHP related knowledge, please visit PHP Tutorial!
The above is the detailed content of About errors encountered in PHP development. For more information, please follow other related articles on the PHP Chinese website!