Summary: no matter how careful we are when writing a program, mistakes are always inevitable. These errors often confuse the PHP compiler. If developers cannot understand the meaning of the error message returned by the compiler, these error messages are not only useless, but also
Summary: no matter how careful we are when writing a program, mistakes are always inevitable. These errors often confuse the PHP compiler. If developers cannot understand the meaning of the compiler error messages, these error messages are not only useless, but often frustrating.
No matter how careful we are when writing a program, errors are always inevitable. These errors often confuse the PHP compiler. If developers cannot understand the meaning of the compiler error messages, these error messages are not only useless, but often frustrating.
When compiling a PHP script, the PHP compiler will do its best to report the first title it encountered. In this way, a title is generated: only when an error is displayed can PHP recognize it (this title is described later in this article ). For this reason, the compiler points out the wrong line. on the surface, the syntax may be correct, or it may be a line that basically does not exist!
A better understanding of error information can greatly reduce the time it takes to determine and correct the error content. Therefore, in this article, I will try to clarify a variety of different types of PHP error messages, and how to accurately understand the meaning of various error messages during the development process.
The content described in this article has nothing to do with the PHP version you are using, because the various errors described in this article are not limited to the specific errors of a special version. In addition, we assume that you are a low-level or intermediate programmer and have been engaged in programming for six months or a year. How the compiler works
To understand why the compiler reports errors on a certain line, you must first understand the mechanism by which the compiler parses PHP code. I am not going to discuss this in detail in this article, but we will discuss some simple concepts that are easier to cause errors.
Variable Declaration
The following describes how to declare a variable in a statement:
$ Variable = 'value ';
The compiler first calculates the value of the right half of the statement (that is, all content on the right of the equal sign ). In some programming books, this is represented by the RHS (right half) of the statement ). It is precisely this part of the statement that often causes errors. If the syntax of the application is incorrect, a parsing error is displayed.
Parsing error
Parse error: Parsing error, unexpected T_WHILE in c: \ program files \ apache group \ apache \ htdocs \ script. php on line 19
Each time the previous error is determined, resolution errors are constantly presented one by one. Since PHP stops executing the script after the first parsing error, debugging and correcting this series of errors is often annoying.
In addition, parsing errors have very little information, and almost no error row is reported. The specific reason is that when an error occurs, the compiler determines that the syntax of several rows should be valid until it encounters an invalid syntax. the most likely case is that the expression applies a predefined word, for example;
While = 10; // Bad? While IS a predefined term and cannot be assigned to a value.
Pre-defined words include while, function, etc. If PHP app uses to evaluate your code. you cannot use these predefined words to name Variables. if you want to do so, PHP will report more errors.