Home > Article > Backend Development > What are the error types in PHP?
In PHP, errors may occur due to grammatical or logical problems; therefore, PHP errors can be divided into several types. This article will take you through the error types of PHP, I hope it will be helpful to you.
Types of Errors in PHP
There are various types of errors in PHP, but it basically There are four main types of errors. Let's take a look at these four main types of errors:
1. Parsing errors or syntax errors:
This is done by the programmer in the program source code error type. Syntax errors are caught by the compiler. After fixing the syntax errors, the compiler compiles the code and executes it. Parsing errors can result from undisclosed quotes, missing or extra parentheses, unclosed braces, missing semicolons, and more.
Example:
<?php $x = "php中文网"; y = "m.sbmmt.com"; echo $x; echo $y; ?>
Error report:
Explanation: In the above program, the $ symbol is missing in line 3, so it An error message is given.
2. Fatal error:
This is the type of error where the PHP compiler understands the PHP code but it identifies an undeclared function. This means calling a function without a function definition.
Example:
<?php function add($x, $y) { $sum = $x + $y; echo "sum = " . $sum; } $x = 0; $y = 20; add($x, $y); diff($x, $y); ?>
Error:
Explanation: In line 10, the function diff() is called, but the function diff The declaration of () is not defined, so it gives an error.
3. Warning errors:
The main reason for warning errors is missing files, which also means that the PHP function calls the missing files.
Example:
<?php header("content-type:text/html;charset=utf-8"); $x = "PHP中文网"; include ("header.php"); echo $x . ",网址为:m.sbmmt.com"; ?>
Error:
Description: The program calls an undefined file header.php that is not available, so it An error will occur.
4. Note the error:
It is similar to a warning error, which means that the program contains an error, but it allows the execution of the script.
<?php header("content-type:text/html;charset=utf-8"); $x = "PHP中文网"; echo $x; echo $y; ?>
Error:
Description: This program uses an undeclared variable $y, so it gives the error message.
Common error constants in PHP
Let’s take a look at the common error constants and their descriptions in PHP:
E_ERROR: Fatal error that causes the script to terminate
E_WARNING: Run-time warning that does not cause the script to terminate
E_PARSE: Compile-time parsing error.
E_NOTICE: Runtime notification due to an error in the code
E_CORE_ERROR: Fatal error occurred during PHP initial startup (installation)
E_CORE_WARNING: Occurred during PHP initial startup WARNING
E_COMPILE_ERROR: Fatal compile-time error with script indicating problem.
E_USER_ERROR: User-generated error message.
E_USER_WARNING: User-generated warning message.
E_USER_NOTICE: User-generated notification message.
E_STRICT: Runtime notification.
E_RECOVERABLE_ERROR: Trapable fatal error indicating a dangerous error
E_DEPRECATED: Runtime notification.
The above is the entire content of this article, I hope it will be helpful to everyone's study. For more exciting content, you can pay attention to the relevant tutorial columns of the PHP Chinese website! ! !
The above is the detailed content of What are the error types in PHP?. For more information, please follow other related articles on the PHP Chinese website!