What is a Parse Error?

If the PHP code contains a syntax error, the PHP parser cannot interpret the code and stops working.

For example, a syntax error can be a forgotten quotation mark, a missing semicolon at the end of a line, missing brackets, or extra characters. This leads to a parse error, because the code cannot be read and interpreted correctly by the PHP parser.

The corresponding error message does not necessarily display the exact line in which the error is located. In the following example, the trailing quotation mark is missing in line 2, but the parser will refer you to line 5 in the error message.

<?php
echo "Hello World!; 
this();
that();
?>

The parser will display an error message similar to this one:

Parse error: syntax error, unexpected end of file, expecting variable (T_VARIABLE) or ${ (T_DOLLAR_OPEN_CURLY_BRACES) or {$ (T_CURLY_OPEN) in /homepages/12/d1123465789/htdocs/index.php on line 5

Please note: To avoid potential errors in missing or adding extra characters that should not be there, you can first put both sets of quotation marks or brackets, before you fill them with code. You can also use an editor that automatically enters the closing characters or highlights errors in the code for you.