PHP programming error correction Guide

Source: Internet
Author: User
Tags parse error

Recently, PHP has become one of the most popular scripting languages thanks to its powerful and easy-to-use features. This article will introduce in detail the problems that users often encounter when using PHP, including syntax errors, program running errors, and logic errors, it is expected to help users who are currently learning the PHP language. In addition, this article will summarize the various precautions in the PHP programming process at the end of the article for your reference.
A notable feature of the PHP script language is that it can automatically generate variable instances without requiring users to declare the variables they need. This feature is worthy of praise, but it also paves the way for the user to write the script program. In good terms, users no longer need to declare every variable to be used in the program at the beginning of the program, as in the C language; however, now you must be very careful about the correct spelling of each variable name. Otherwise, a new variable may be created unintentionally. Some programming languages, such as PERL, can record the information of the variables used only once in the program, and issue a warning prompt based on the user's preset settings. In addition, PERL provides a powerful debugger. As of version 4.0.2, the PHP language does not contain a debugger. However, this does not affect the popularity and promotion of PHP language. PHP provides a wide range of functions, even compared to mature programming languages like C. It can be said that PHP is currently one of the most convenient scripting languages with the most comprehensive WEB support functions.
Next, let's get down to the truth and take a look at what problems are prone to in the PHP programming process, and what measures should be taken accordingly.
The use of semicolons is just as we usually have to end each sentence at the end of the article, PHP requires that each statement in the program must end with a semicolon. This is the most basic syntax rule, but it is also the most prone to problems. When writing a program, we seldom check whether a semicolon is missing in a row or line, but once there is any negligence, the parsing program will issue an error report immediately. Sometimes, the report may contain the number of problematic statements.
$ #@ 60 ;?
$ Output = "Hello World ";
Echo $ Output
$ Other = "Blah ";
Print $ SomeMoreText;


? $ #@ 62;
A semicolon is missing at the end of the second line "echo $ Output" of the above Code. If you execute this script, the following error message will be generated:
Parse error: parse error, expecting '','' or '';'' in/usr/local/apache/htdocs/test. why is the error reported in the php on line 8 report? The comma "," or Semicolon ";" is missing, but the problematic statement is set to the eighth line. Because this code is very simple, we can easily find the real error. However, if the program is very complex, it is difficult to find out the errors smoothly.
Based on my previous experience, the following methods are recommended:
If the statements in the error report do not have obvious problems, you can check whether other command lines (excluding comment lines) that are located before the statement are correct. If no error is found, comment out the statement line in the report (Add "//" or "#" at the beginning of the statement line) you can also change to other statements that can ensure that there is no problem at all. Then run the program again. If the error prompt still points to the same line, it indicates that the problematic statement should be located before the commented-out statement line. Check each line of commands in front of each position one by one according to the above method until the error message changes. At this time, we have successfully dug out the real culprit.
Variables are different from other programming languages that require users to explicitly declare variables. PHP allows users to automatically use all variables without having to declare them in advance. Misspelling of variable names has become a major problem for PHP users.
$ #@ 60 ;?
Function Combine ($ FirstHalf, $ SecondHalf)
{
$ Combined_String = $ FirstHalf. $ SecondHalf;
Return $ Combined_String;
}
$ FirstString = "WDVL -";
$ SecondString = "inclustrated Encyclopedia ";
$ Combine_Result = Combine ($ FirstString, $ SecondString );
Print $ Combined_Result;
? $ #@ 62;
When we run the above script, we will see the error message because the program does not return any data. Here, we chose a very intuitive example to better illustrate the problem. In reality, sometimes the problem is not that simple. I believe everyone has found the cause of the problem, that is, the variable name "$ Combined_Result" in "print $ Combined_Result;" should be changed to "$ Combine_Result ".

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.