On the Acquia blog Adam Weingarten has shared some tips for writing good (and modern) object-oriented code in PHP:
Recently I began working on a D8 module, but this isn't a story about a D8 module. The work I did provided me an opportunity to get back to my pre-Drupal object oriented (OO) roots. Writing OO code in PHP presented some curve balls I wasn’t prepared for. Here are some of the issues I encountered:
His tips touch on things like:
- Using a code structure that can be autoloaded via PSR-4
- Namespacing your classes
- Working with types and type hinting
- Using docblock comments for autocomplete in IDEs
There's also a few other quick topics he finishes the post out with: the lack of enums in PHP, working with associative arrays, no functional overloading and assigning responsibility to classes.