This article mainly introduces the solutions to some errors encountered in PHP development. It has certain reference value. Now I share it with you. Friends in need can refer to it
In program development and debugging During the error process, we will always encounter various error
, some error
will affect the execution of the code, and some will just give a WARNING
or NOTICE
will not affect the continued execution of the following code.
PHP
provides an error control operator @
, which when placed before a PHP
expression, Any error messages that may be generated by the expression are ignored. If you want to control the type of output error, you can tell the compiler what kind of error should be reported through the error_reporting()
function.
int error_reporting ([ int $level ] )
: Set what kind of PHP
errors should be reported $level
is the error level, returning the old [error_reporting]
level, or the current level if the level
parameter is not given.
<?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 the predefined constants of PHP
:
We often encounter them in development The ones are E_ERROR
, E_WARNING
, E_PARSE
, E_NOTICE
.
The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
How to use PHP to upload multiple videos at the same time
The above is the detailed content of Solutions to some errors encountered in PHP development. For more information, please follow other related articles on the PHP Chinese website!