Home >Backend Development >PHP Problem >What are the php errors?

What are the php errors?

青灯夜游
青灯夜游Original
2021-07-19 20:23:333626browse

php errors are generally divided into three categories: 1. Syntax errors, which are the easiest errors to encounter and solve in programming; 2. Runtime errors, which are errors that occur when the program is executed. ;3. Logic error, the program will execute normally, but the output result is not what we expect.

What are the php errors?

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

Any programmer may or More or less, some mistakes may occur, or errors may occur for other reasons. Of course, if the user is unwilling or does not follow the constraints of the application, some errors may occur during use.

Errors in PHP programs are generally divided into three categories, namely syntax errors, execution errors and logic errors. The following are introduced respectively:

1. Syntax error

Syntax error is the most common error in programming and the easiest to solve, such as: missing an error A semicolon will display an error message. This error stops program execution and displays an error message. We can correct the program based on the error message and re-execute it.

[Example] The following uses simple code to demonstrate common syntax errors and related error messages.

<?php
    $a = 1;
    $b = 2;
    $c = $a + $b
    echo ;
?>

; is omitted at the end of line 4 in the above code, so running the above code will display the following error message:

Parse error: syntax error, unexpected &#39;echo&#39; (T_ECHO) in D:\WWW\index.php on line 5

As can be seen from the above example and running results, syntax errors will Prevents the program from continuing downward execution. Only after these errors are resolved can the program execute smoothly.

2. Run-time errors

Run-time errors are also errors that occur when the program is executed. There is no syntax error in this kind of program, but during execution, PHP will find some unreasonable aspects of the program and prompt a warning message, but the program will continue to execute.

[Example] Using 0 as the divisor will cause the program to run incorrectly and output an error message.

<?php
    $a = 1;
    $b = 0;
    $c = $a / $b;
    echo "$a / $b = $c";
?>

The running results are as follows:

Warning: Division by zero in D:\WWW\index.php on line 4 1 / 0 = INF

3. Logic error

Logic error is an error that occurs in the programmer's mind. There is no obvious error message when a logic error occurs, because the program will not report any error message during execution, and the program will execute normally, but the output result is not what we expect.

[Example] The following demonstrates logical errors and their output results through simple code.

<?php
    $a = 1;
    $b = 2;
    if($a = $b){
        echo &#39;$a = $b&#39;;
    }else{
        echo &#39;$a != $b&#39;;
    }
?>

The running results are as follows:

$a = $b

As you can see from the above example, there will be no prompt message for logical errors. The only way to avoid this is for programmers to pay more attention when writing programs. This is still a very short piece of code. If the amount of code is particularly large, it will be very time-consuming to modify.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What are the php errors?. For more information, please follow other related articles on the PHP Chinese website!

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