PhpRiot
News Archive
PhpRiot Newsletter
Your Email Address:

More information

The danger of privates, and composition vs. inheritance

Note: This article was originally published at Planet PHP on 12 December 2012.
Planet PHP

The private variables debate is going around the PHP world again. Brandon Savage posted a pair of articles pointing out the perils of private variables, boiling down mostly to them making extension infesible or impossible. Anthony Ferrara replied with his own article, arguing that the real problem is using inheritance in the first place rather than composition. I figured I'd weigh in on my own blog rather than in a comment. :-)

As an academic matter, I agree with Anthony. Composition and interfaces are more flexible than inheritance. I've been preaching the interface gospel within Drupal almost as long as I've been preaching Dependency Injection.

read more