Membership
Main Menu
Forum Boards
Stats
- 18 tutorials
- 72,296 members
- 695,940 forum posts
- 11 blog posts
Tutorials
Debugging: A Beginner's guide
Views: 25997
Syntax Errors -- Debugging
Computers are stupid. You can quite easily understand something with a missing piece of punctuation, but computers? They throw their teddies out the pram. You might, for instance, see this:
Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\phpfreaks.php on line 3
Now, when something's unexpected, it means just that. However, it does not always mean that it's not required. For example, the above error message was generated with this code:
The unexpected element of the above is $bar. But we wanted to define $bar, that's not unexpected. What is unexpected is the lack of semi-colon on the previous line. This leads us to one important aspect of finding and fixing errors: check the previous lines.
Other common causes of syntax errors are:
- Unclosed quotes
- Missing or Extra parentheses (for example, with if statements)
- Unclosed braces -- more on this later
One thing that will help you avoid making syntax errors is the use of a good editor with syntax highlighting. This will make things such as unclosed quotes very obvious.
We'll move onto fatal errors, warnings and notices on page 4.
