Home  >  Article  >  Backend Development  >  PHP error debugging_PHP tutorial

PHP error debugging_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:45:52854browse

There are three main categories of Php errors:
1. Grammatical errors
In this case, when the program is executed, an error message (error report) will usually be displayed. This type of error prevents the page php script from performing other tasks. Such as:
Echo 100.
Echo 100;
Echo 101;
?>
Execution results

Parse error: syntax error, unexpected ';' in…

2. Runtime error
It will not prevent the php script from running, but it will prevent the script from doing what it wants to do. As follows:
echo “this is a demo”;
header('Location: http://www.example.com/');
//There cannot be any output before header() header() must be called before any actual output
?>

Execution result:
this is a demo

Warning: Cannot modify header information - headers already sent by (output started at E:PhpProject1test.php:7) in E:PhpProject1test.php on line 8


3. Program logic error
This error will not prevent the execution of the php script, nor will it display an error message. The commonly used debugging method is exception handling. Such as
$a=5;
If($a=6){
Echo $a;
}
?>
The running result is 6



Error reporting level:
Error ERROR
The page script will stop running
WARNING
The page script will not stop running
NOTICE
Page scripts won’t stop running

/*
*ini_set()
*error_reporting()
*header()
*
*/


header(“Content-type:text/html;charset=utf-8”);


echo $a; //Notice: Undefined variable: a
echo "
++++++++++++++++++++
";
echo "this is a Notice:Undefined variable";


echo “

”;
var_dump();
echo "
++++++++++++++++++++++
";
echo "This ia a Warning level Warning: Wrong parameter count for var_dump()...";


echo “

”;
ech “This is a demo”;
echo "
++++++++++++++++++++++
";
echo "This ia a Warning level Warning: Wrong parameter count for var_dump()...";
?>



ini_set()
Sets the value of a configuration option
string ini_set ( string $varname , string $newvalue )
Sets the value of the given configuration option. The configuration option will keep this new value during the script's execution, and will be restored at the script's ending.
Assign a value to the given (specified) configuration option. During the execution of the program, the configuration option will keep using this newly assigned value. When program execution is complete, configuration options are restored to the system's default values.
ini_set(‘display_errors’,1); Turn on display_errors
in php.ini
error_reporting(E_ALL);
All errors, warnings, and notes of the error reporting program.



error_reporting(E_ALL);
ini_set(‘display_errors’,1);
Author "My PHP Road"

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478645.htmlTechArticleThe categories of Php errors mainly include the following three categories: 1. Syntax errors. This situation usually occurs when the program is executing Sometimes, an error message (error report) will be displayed. This type of error will prevent the page from p...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn