PHP: Syntax errors

If a PHP program isn't syntactically correct, the interpreter will show a relevant message and point you to the file and the line where the error has possibly occured. Syntax errors occur when the code has grammar mistakes. Grammar rules are important in human languages, grammar mistakes won't affect your ability to read or understand any text. In programming, however, we must follow rules to the letter. Even a tiny mistake can halt your program. A wrong parenthesis order, forgetting to add a semicolon ; — these are just few examples of such mistakes.

Here is an example of code with a syntax error:



If we run this code we will see the following message: $ PHP Parse error: syntax error, unexpected end of file in /private/var/tmp/index.php on line 4. In PHP such errors are called "Parse error". As we can see it includes a file path and a line number.

On one hand, parse errors are the simplest because they are all about code grammar rules and aren't related to any code logic. They can be easily fixed, you just need to find where the syntax is incorrect.

On the other hand, the interpreter will not always tell you the exact location of an error. Sometimes you need to add a missed bracket to another place as opposed to what the error message says.


Print to screen the following phrase: What Is Dead May Never Die.


  • Syntax error - violation of grammar rules in a programming language

  • Parse error - type of errors in PHP caused by syntax errors in the code

If you got stuck and don't know what to do, you can ask a question in our huge and friendly community