Take you to understand the error types and error levels of PHP
In the previous article, I brought you "Five minutes to help you understand what exception handling is in PHP", which introduced in detail the issues related to PHP exception handling. This article In this article, let’s continue to take a look at the relevant knowledge of PHP error handling, PHP error types and PHP error levels. I hope it will be helpful to everyone!

It is inevitable that programmers will make some mistakes during the development process, or errors may occur due to other reasons. At this time, it is necessary for us to understand what is in PHP Error types and error levels. You can also click on the free "php Error Handling" teaching video to learn related knowledge.
PHP error types
PHP program errors are generally divided into three categories, which are syntax errors, execution errors and logic errors.
Grammar errors
Grammar errors are the most common in programming This is one of the easiest errors to fix. For example, an error message is displayed when a semicolon is missing. This error stops program execution and displays an error message. We can correct the program based on the error message and re-execute it.
Grammar errors can be said to be the most common type of error we encounter in the programming process. At the same time, I think it is also the easiest error to solve; for example: forgetting to enter a semicolon when typing. Or the function syntax is wrong.
<?php
$a = 1
echo $a;
?>In the above example, there is a semicolon missing at the end of the second line, and the output result is incorrect.
After adding the semicolon, the program runs normally and the output result is 1. From this we can see that when a syntax error occurs, the program will stop and continue to execute. When the syntax error is resolved, the program can continue to execute.
Run-time error
Run-time error is the process of running the program An error occurs in the program. What needs to be noted at this time is that there is no syntax error, but during the execution process, PHP will warn you that there is something unreasonable in the program. Unlike syntax errors, the program will continue to run downwards.
The example is as follows:
<?php
$a = 1;
$b = 0;
$c = $a / $b;
echo "$a / $b = $c";
?>In the above example, there is no syntax error, but 0 cannot be used as a divisor, and the output result is:

Logic error
The program with logic error will execute normally, but the output The result was wrong. The root cause occurred in the code we wrote. There was no alarm message during the execution of the program. The example is as follows:
<?php
$a = 1;
$b = 2;
if($a = $b){
echo '$a = $b';
}else{
echo '$a != $b';
}
?>Output result:

We can see from the above example that the output result is obviously wrong and illogical. , when a logic error occurs, there is no alarm message. This requires us to be more vigilant and avoid logical errors.
Expand knowledge: PHP error levels
There are both error types and error levels defined in PHP. The error levels can be defined in php.ini. (Click "How to upload files in PHP? You will understand after reading this!" to see how to find php.ini)
The error types in PHP are as follows:
1 ---E_ERROR---A fatal runtime error is generally an unrecoverable situation, such as a problem caused by memory allocation. The consequence is that the script terminates and no longer runs.
2 --- E_WARNING --- Runtime warning (non-fatal error), only prompt information is given, but the script will not terminate the operation.
4 --- E_PARSE --- Compile-time syntax parsing error, generated only by the analyzer.
8 --- E_NOTICE ---Runtime notification, indicating that the script encounters a situation that may appear as an error, but there may also be similar errors in scripts that can run normally. notify.
16 --- E_CORE_ERROR --- A fatal error that occurs during the PHP initialization startup process, similar to E_ERROR, but generated by the PHP engine core.
64 --- E_COMPILE_ERROR --- Fatal compile-time error, similar to E_ERROR, but generated by the Zend script engine.
128 --- E_COMPILE_WARNING --- Compile time warning (non-fatal error), similar to E_WARNING, but generated by the Zend script engine. .
1024 --- E_STRICT --- Enable PHP's suggestions for code modifications to ensure the best interoperability and forward compatibility of the code.
8192 --- E_DEPRECATED --- Runtime notification, when enabled, will give a warning for code that may not work properly in future versions.
16384 --- E_USER_DEPRECATED --- The warning message generated by the user is similar to E_DEPRECATED, but it is generated by the user himself using the PHP function trigger_error() in the code.
30719 --- E_ALL --- All error and warning messages except E_STRICT.
If you want to know more about PHP, you can click on "PHP Video Tutorial" to learn!
The above is the detailed content of Take you to understand the error types and error levels of PHP. For more information, please follow other related articles on the PHP Chinese website!
PHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AMPHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.
PHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AMPHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.
Choosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AMPHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.
PHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AMPHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.
PHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AMPHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip
How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AMPHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.
How does PHP handle object cloning (clone keyword) and the __clone magic method?Apr 17, 2025 am 12:24 AMIn PHP, use the clone keyword to create a copy of the object and customize the cloning behavior through the \_\_clone magic method. 1. Use the clone keyword to make a shallow copy, cloning the object's properties but not the object's properties. 2. The \_\_clone method can deeply copy nested objects to avoid shallow copying problems. 3. Pay attention to avoid circular references and performance problems in cloning, and optimize cloning operations to improve efficiency.
PHP vs. Python: Use Cases and ApplicationsApr 17, 2025 am 12:23 AMPHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft







