One of the greatest pains of jumping between different programming languages is the different syntax rules and the obscure error messages you get when you violate these rules. You stare at the code, the error message and nothing makes sense, especially if you are not using an IDE. It was when I was facing such a mistake that I got the idea for this post. So I'll start with that.
1. In PHP variables are denoted with '$' not '@'.
You can guess that I'd been doing some Ruby programming before this. The code I wrote was:
@usr = new StdClass();
The error message was 'Parse error: syntax error, unexpected '=' in
on line . How cryptic is that! I should have typed: '
$usr = new StdClass();
However, just @usr; is a valid PHP statement!
2. Where to put those semicolons?
Semicolons are neat statement delimiters. Where to put them and where not to is an error that's easy to make and easy to pick up but worth a mention.
Of the programming languages I use the following use semicolons:
- Visual Basic .NET (and VB6)
Next post I'll look at the "if, elseif, else if, elif, end if, then" dilemma, Case Sensitivity, Whitespace (tabs vs space), Comments and much more. Share your pain in the comments.