Markdown

[PHP] Parse/Syntax Errors; and How to solve them?

https://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them

Everyone runs into syntax errors. Even experienced programmers make typos. For newcomers it's just part of the learning process. However, it's often easy to interpret error messages such as:
PHP Parse error: syntax error, unexpected '{' in index.php on line 20
The unexpected symbol isn't always the real culprit. But the line number gives a rough idea where to start looking.
Always look at the code context. The syntax mistake often hides in the mentioned or in previous code lines. Compare your code against syntax examples from the manual.
While not every case matches the other. Yet there are some general steps to solve syntax mistakes. This references summarized the common pitfalls:
Closely related references:
And:
While Stackoverflow is also welcoming rookie coders, it's mostly targetted at professional programming questions.
  • Answering everyones coding mistakes and narrow typos is considered mostly off-topic.
  • So please take the time to follow the basic steps, before posting syntax fixing requests.
  • If you still have to, please show your own solving initiative, attempted fixes, and your thought process on what looks or might be wrong.
If your browser displays error messages such as "SyntaxError: illegal character", then it's not actually -related, but a -syntax error.

留言