PHP error reporting

Time:2021-7-26

What kinds of error tips does PHP have

1. Notice: Note
2. Warning: warning
3. Error: error

1. Note that these are relatively small and not serious errors, such as accessing an undefined variable. Usually, such errors are not prompted to the user, but sometimes these errors will affect the running results.
PHP error reporting
PHP error reporting

2. Warnings: This is a slightly more serious error. For example, you want to include () a file that does not exist itself. Such an error message will prompt the user, but will not cause the program to terminate.

3. Fatal errors these are serious errors. For example, if you want to initialize an object of a nonexistent class or call a nonexistent function, these errors will cause the program to stop running, and PHP will show these errors to the user.
PHP error reporting
PHP error reporting
PHP error reporting
PHP error reporting
PHP error reporting
PHP error reporting
PHP error reporting

1. Syntax error

Syntax error is the most easily encountered and solved error in programming. For example, error information will be displayed when a semicolon is omitted. This error stops the execution of the program and displays an error message. We can correct the program according to the error information, and then execute it again.

[example] the following is a simple code to demonstrate common syntax errors and related error messages.

1.  <?php
2.      $a \= 1;
3.      $b \= 2;
4.      $c \= $a + $b
5.      echo ;
6.  ?>

Omitted at the end of line 4 in the above code;Therefore, running the above code will display the following error message:

Parse error: syntax error, unexpected 'echo' (T\_ECHO) in D:\\WWW\\index.php on line 5

As can be seen from the above examples and running results, syntax errors will prevent the program from continuing downward execution. Only after these errors are solved can the program be executed smoothly.

2. Runtime error

Runtime errors are also errors that occur just when the program is executing. There is no syntax error in this program, but during execution, PHP will find some unreasonable places in the program and prompt a warning message, but the program will continue to execute downward.

[example] Taking 0 as the divisor will cause program operation error and output error information.

1.  <?php
2.      $a \= 1;
3.      $b \= 0;
4.      $c \= $a / $b;
5.      echo "$a / $b = $c";
6.  ?>

The operation results are as follows:

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

3. Logical error

Logic error is a kind of 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 is a simple code to demonstrate logic errors and their output results.

1.  <?php
2.      $a \= 1;
3.      $b \= 2;
4.      if($a \= $b){
5.          echo '$a = $b';
6.      }else{
7.          echo '$a != $b';
8.      }
9.  ?>

The operation results are as follows:

$a = $b

As can be seen from the above example, there will be no prompt message for logical errors. If you want to avoid it, you can only rely on programmers to pay more attention when writing programs. It takes a lot of time to modify the code.
Summary:
1. Make more mistakes and solve more mistakes.
2. Be careful to avoid making mistakes (repetitive mistakes).
PHP error reporting

Recommended Today

VBS obtains the operating system and its version number

VBS obtains the operating system and its version number ? 1 2 3 4 5 6 7 8 9 10 11 12 ‘************************************** ‘*by r05e ‘* operating system and its version number ‘************************************** strComputer = “.” Set objWMIService = GetObject(“winmgmts:” _  & “{impersonationLevel=impersonate}!\\” & strComputer & “\root\cimv2”) Set colOperatingSystems = objWMIService.ExecQuery _  (“Select * from […]