My experience has primarily been in Java, but I'm working on a PHP project and conscious of my lack of knowledge of idiomatic PHP. What resources (online or print) will help me avoid making the mistakes that people with Java goggles normally make? First prize would be something that would give me short in-depth examinations of important PHP ideas, a la Joshua Bloch's Effective Java.
closed as off-topic by MichaelT, Ampt, jwenting, gnat, Bart van Ingen Schenau Jun 5 at 8:06
This question appears to be off-topic. The users who voted to close gave this specific reason:
As a professional PHP programmer (with a CS degree and exposure to idiomatic Java and idiomatic Ruby amongst other things) I've found that PHP idioms really depend on the framework (or lack thereof) that you're using.
It's quite possible - and, in my personal opinion, very sensible - to write PHP in a Java-ish style. Many of the best frameworks (Zend, Doctrine, PHPUnit, Facebook's various bits and bobs) will feel comfortable if you do so. Although PHP is weakly typed, making use of the strong typing features will enable you to make the most of server utilities such as Facebook's HiPHoP compiler.
I have come across many idioms in PHP, however, some of which are project dependent. Anything with its roots in PHP4 will probably feel more like C or Perl, with extensive use of includes, structs (i.e objects where all props are public) and global functions.
Some of the newer features in PHP5.3 (such as closures) are designed to make porting code from languages such as Ruby easier, although it will not feel idiomatic if you do, as it makes for ugly PHP.
When using PHP as a tempting language - anyone who's seen a Wordpress theme will know what I mean - you will find a different set of idioms comes into play. Even so, I've never yet come across a PHP templating idiom that felt as natural as Rails RHTML or Java's XML based stuff - except for Facebook's XHP language extension, and that's not widely supported anywhere else.
Having said all that, here are my prime language tips: