Home > Backend Development > PHP Tutorial > PHP programming error correction guide_PHP tutorial

PHP programming error correction guide_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 17:21:52
Original
939 people have browsed it

In recent times, PHP has been loved and accepted by more and more people due to its powerful functions and simple and easy-to-use features, and has become one of the most popular scripting languages. This article will give a detailed introduction based on the problems that users often encounter when using PHP, including syntax errors, program running errors and logic errors. I hope it will be helpful to those users who are currently learning the PHP language. In addition, this article will also summarize various matters that should be paid attention to during PHP programming at the end of the article for readers' reference.
A notable feature of the PHP scripting language is that it can automatically generate variable instances without requiring users to declare the variables they need to use. This feature is commendable, but it also creates hidden dangers for scripts written by users. On the plus side, users no longer need to declare every variable that will be used in the program at the beginning of the program like using C language; however, now users must be very careful about the correct spelling of each variable name, otherwise It is possible to create new variables unintentionally. Some programming languages, such as PERL, can record information about variables that are only used once in the program and issue warning prompts based on the user's preset settings. In addition, PERL also provides a very powerful debugger. As of version 4.0.2, a debugger is not included in the PHP language. But this has not affected the popularity and promotion of the PHP language. PHP provides a very wide range of functions, even compared with mature programming languages ​​​​such as C. It can be said that PHP is one of the scripting languages ​​that is currently the most convenient to use and has the most complete WEB support.
Next, let us get back to business and take a look at what problems are likely to occur in the PHP programming process and what corresponding countermeasures should be taken.
The use of semicolons is just like when we usually write articles, we must add a period at the end of each sentence. PHP requires that every statement in the program must be ended with a semicolon ";". This is the most basic grammatical rule, but it is also the most prone to problems. When we write a program, we rarely check line by line for missing semicolons, but once any oversight occurs, the parser will immediately issue an error report. Occasionally, the report may include the number of statement lines where the problem occurred.
$#@60;?
$Output="Hello World";
echo $Output
$Other="Blah";
print $SomeMoreText;


 ?$#@62;
 We missed a semicolon at the end of the second line of the above code "echo $Output". If the script is executed, the following error message will be generated:
 Parse error : parse error, expecting `','' or `';'' in /usr/local/apache/htdocs/test.php on line 8. Although the report pointed out the cause of the error? The comma "," or sub ";", but the problematic statement is placed on the eighth line. Because this code is so simple, we can easily find where the error actually occurs. However, if the program is very complex, it will be difficult to find errors smoothly.
Based on the author’s past experience, the following method is recommended:
If there is no obvious problem with the statement pointed out in the error report, you can check whether other instruction lines (excluding comment lines) before the statement are correct. If the error is still not found, you can comment out the statement line pointed out in the report (add the "//" or "#" comment symbol at the beginning of the statement line) or change it to other statements that the user can ensure that there is no problem at all. After that, rerun the program. If the error message still points to the same line, it means that the real problematic statement should be located before the commented out statement line. Follow the above method to check each line of instructions at the front one by one until the error message changes. At this time, we successfully dug out the real culprit.
The problem with variables is different from other programming languages ​​that require users to explicitly declare variables. The PHP language allows users to automatically use all variables without prior declaration. Misspelling of variable names has become a big problem for PHP users.
$#@60;?
function Combine ($FirstHalf, $SecondHalf)
{
$Combined_String=$FirstHalf.$SecondHalf;
return $Combined_String;
}
$FirstString="WDVL - ";
$SecondString="Illustrated Encyclopedia";
$Combine_Result=Combine ($FirstString, $SecondString);
print $Combined_Result;
?$#@62 ;
When we run the above script, we will see an error message because the program does not return any data. Here, we have chosen a very intuitive example to better illustrate the problem. In reality, sometimes the problem is not so 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".

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532389.htmlTechArticleIn recent times, PHP has been loved by more and more people due to its powerful functions and simple and easy-to-use features. and accepted, becoming one of the most popular scripting programming languages. This article will be combined with...
source:php.cn
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template