php error_reporting () given off

Error reporting level: specifies under what circumstances, script code errors (error here is generalized errors, including E_NOTICE attention, E_WARNING warning, E_ERROR fatal error, etc.) will be output as error reporting.

A commonly used instructions provided

error_reporting (-1); displays all PHP error reporting, including the new PHP error level in the future to join. To PHP5.4, E_ALL have the same behavior. 

error_reporting (0); PHP represents off all error reporting 

error_reporting (7); denotes a display E_ERROR (1) | E_WARING (2 ) | E_PARSE (4) == (1 + 2 + 4)

Two, error_reporting Function Description

error_reporting - set which PHP errors should be reported

Explanation

int error_reporting ([ int $level ] )

error_reporting () function can be provided error_reporting instructions at runtime. PHP has many levels of errors, using this function can set the level of when the script runs. If you do not set the optional parameter level, error_reporting () will only return the current error reporting level.

Parameter level

The new error_reporting level. May be a bit mask can also be a named constant. It is strongly recommended to use a named 常量, in order to ensure compatibility with future versions. Since the error level is added to increase the integer value range, longer is not always consistent with integer-based error levels and expected performance.
Error level constants and the actual meanings available are described in the predefined constants in.

Value Constant Description Note
1 E_ERROR (integer) Fatal run-time errors. Such errors are generally unrecoverable situation, such as memory allocation problems caused. Consequence of this is the script to terminate not continue to run. 
2 E_WARNING (integer) Warnings (non-fatal error) is running. Only give prompt information, but the script does not terminate. 
4 E_PARSE (integer) parsing errors at compile time. Parsing error is produced by the analyzer. 
Notification runtime 8 E_NOTICE (integer). It indicates that the script encountered may manifest itself as an error, but the script running inside there may be similar notice. 
16 E_CORE_ERROR (integer) Fatal errors that occur during the initial startup PHP. The error is similar to E_ERROR, but is generated by the PHP engine core. since PHP 4
warnings (non-fatal error) occurred 32 E_CORE_WARNING (integer) PHP initialization during startup. Similarly E_WARNING, but is generated by the PHP engine core. PHP 4 Operating since
64-E_COMPILE_ERROR (Integer) fatal error when compiling. Similarly E_ERROR, but it is generated by the Zend Scripting Engine. PHP 4 Operating since
128 E_COMPILE_WARNING (Integer) warnings (non-fatal errors) at compile time. Similarly E_WARNING, but is generated by the Zend Scripting Engine. since PHP 4
error message 256 E_USER_ERROR (integer) user-generated. Similarly E_ERROR, but using PHP function trigger_error code by the user () which is produced. since PHP 4
512 E_USER_WARNING (integer) user-generated warning message. Similarly E_WARNING, but using PHP function trigger_error code by the user () which is produced. since PHP 4
notification information 1024 E_USER_NOTICE (integer) generated by the user. Similarly E_NOTICE, but is used by the user trigger_error PHP function code () which is produced. PHP 4 Operating since
2048 E_STRICT (Integer) to enable PHP proposed changes to the code, the code has to ensure the best interoperability and forward compatibility. PHP 5 Operating since
4096 E_RECOVERABLE_ERROR (Integer) can be a fatal error to capture. It represents a potentially very dangerous error has occurred, but has not yet led to the PHP engine in an unstable state. If the error is not user-defined handle capture (see set_error_handler ()), will become a E_ERROR so the script will terminate. PHP 5.2.0 Operating since
8192 E_DEPRECATED notice (integer) is running. Will be enabled code may not work in future versions warning. PHP 5.3.0 Operating since
16384 E_USER_DEPRECATED (Integer) user produce fewer warnings. Similarly E_DEPRECATED, but is used by the user trigger_error PHP function code () which is produced. PHP 5.3.0 Operating since
30719 E_ALL (Integer) E_STRICT go of all error and warning messages. 30719 in PHP 5.3.x, 6143 in PHP 5.2.x, 2047 previously

The above value (value or symbol) used to create a binary bit mask, to develop an error message to be reported. Bitwise operators may be used to shield certain values ​​or a combination of these types of errors. Please note that in the php.ini, only '|' '!', '~',, '^' And '&' will be resolved correctly.

? <PHP 
 
// Close all PHP error reporting 
error_reporting (0); 
 
// Report simple running errors 
error_reporting (E_ERROR | E_WARNING | E_PARSE); 
error_reporting (7); 
 
// variable report E_NOTICE also very good (report uninitialized or capture the variable name misspellings) 
error_reporting (E_ERROR | E_WARNING | E_PARSE | E_NOTICE); 
 
// except E_NOTICE, report all other errors 
// this is the default setting in php.ini 
error_reporting (E_ALL ^ E_NOTICE); 
 
// report all PHP errors (see ChangeLog) 
error_reporting (E_ALL); 
 
// report all PHP errors 
error_reporting (-1); 
 
// and error_reporting (E_ALL); as 
ini_set ( 'error_reporting', E_ALL); 
 
?>

If you do not turn off E_NOTICE, the uninitialized variable will be displayed on the page:

clipboard.png

As can be seen in the php_error_log:

clipboard.png

If you add this code to the script, it will not burst this prompt:

error_reporting(E_ALL ^ E_NOTICE);

Third, set the php.ini

Sometimes, PHP code when debugging, error, not prompt is a very sad thing, do not you expect to guess what the problem is? Of course not, even in the beginning of the page is executed  error_reporting(E_ALL), or not found error output, in fact, the reason is that php.inithere will be display_errorsclosed. You can php.inibe inside display_errorsconfigure On, and then restart php-fpm, if both test project, another line item on the server, it is still not open, to prevent others using your mistakes, and attack you .

Just one more item to be tested which can add

ini_set('display_errors','On');

error_reporting(E_ALL);

Fourth, print error messages in PHP script

ini_set ( 'display_errors', 1) ; // error 
ini_set ( 'display_startup_errors', 1) ; // php start error message 
error_reporting (-1); // print out all error messages

Project printing error message:

// 错误信息
@ini_set('display_errors',1);
error_reporting(E_ALL & ~ (E_STRICT | E_NOTICE | E_WARNING));

Determining whether a process has run:

// 判断程序是否有启动
define('runcode', 1);

    $handle = popen("ps -ef | grep redis 2>&1", 'r');
        $cmd_cont = '';
        while(!feof($handle)) {
            $buffer = fgets($handle);
            $cmd_cont .= $buffer;
        }
        pclose($handle);

dump($cmd_cont);

  

Debug script:

? <PHP 

/ ** 
 * --------------------------------- 
 * Debug System - Online Editor 
 * - ------------------------------- 
 * @desc To use the online editor, you need to set constant: define ( ' RUN ',. 1); 
 * @author Corwien 
 * @version 2017-07 
 * --------------------------------- 
 * / 

// load configuration file 
DEFINE ( 'IN_EB', to true); 
DEFINE ( 'root_path', __DIR__ "/."); 

// error 
@ini_set ( 'the display_errors',. 1); 
the error_reporting (E_ALL & ~ (E_STRICT | E_NOTICE | E_WARNING)); 

// initialize 
$ text = isset ($ _ REQUEST [ 'text']) $ _REQUEST [ 'text']: '';? 
preg_match ( "/ the DEFINE \ ( 'RUN', 1 \); / ", $ text) && eval ($ text);
// if($text == '') $text = "define('runcode', 1);";

  


Reprinted: https://segmentfault.com/a/1190000010113821

Guess you like

Origin www.cnblogs.com/lxwphp/p/11367919.html