PHP syntax errors description

Every programming language has number of rules, called syntax, which must be followed in the constructions in order to be valid. If a construction is not following these rules, then we said that there is a syntax error. Syntax errors often are called parser errors, when we talk about languages like PHP. Other errors could be compiler errors like in C or Java.

If we do not follow the rules when we speak or write to other people, probably they will understand, but when we write a PHP script most probably there will be an error.

If a script is not written correctly according to the rules, the PHP parser will not be able to process a part or the whole script. Within many other rules PHP syntax demands all the constructions to end with semicolon, string to be enclosed in quotes and the parameters to be separated with comas and enclosed within brackets.

The PHP errors are very usefully because they are providing us with information, what is wrong with the script.

For example :

PHP Parse error: syntax error, unexpected T_ECHO in /home//public_html/test/date.php on line 3‘ will be generated by a script where you have forgotten to add semicolon.

The interesting part here is that the PHP parser error is reported on line 3 instead on the actual error place on line 2.
Here is one similar situation but harder to be found.

This will generate the following error: ‘PHP Parse error: parse error in /home//public_html/test/date.php on line 4

Since we do not have line 4 it is obvious that there is something wrong. This often happens when you forget to enclose a string or construction.
The following script will generate similar PHP error:

You can imagine what is the filling when you receive an error like: ‘parse error on line 901‘ generated for a file of 900 lines.

In general the syntax errors are easiest to be discovered. IF you make such error PHP often will show you the exact place.

Here is the section where we discuss different PHP Scripts and tricks

Filed Under: PHP

Anthony Gee About the Author: Anthony G. is an IT specialist with more than 9 years of solid working experience in the Web Hosting industry. Currently works as server support administrator, involved in consultative discussions about Web Hosting and server administration. One of the first writers in the Onlinehowto.net website, now writing for Free Tutorials community - he is publishing tutorials and articles for the wide public, as well as specific technical solutions.

Leave a Reply