Archive for 2008

Why Use a PHP Framework?

June 25, 2008

At last night’s NY-PHP gathering, a fellow PHP’er and I discussed PHP frameworks. I told her I was developing an e-commerce site using Zend Framework. She replied that she’d been considering frameworks, especially Cake and Symfony, “but I’m not sure I need a framework at all. I write my own SQL; my apps work fine. What would a framework do for me?”

Setting aside the differences between PHP frameworks, I’m aware of at least 4 reasons to use them:

  1. Modular design : A home-grown application, with its ad hoc growth, can become a tangled mess that’s hard to change or enhance. Most mainstream frameworks provide a modular design that makes it easier to modify or add components.
  2. Flexible components : Sure, you can write your own authorization class in PHP, but why reinvent the wheel? The framework will provide an integrated component that handles not only your current needs, but requirements that you haven’t yet encountered (but that the framework’s community has). With a framework, chances are that you won’t have to re-architect your authorization system when the users ask for something new.
  3. Best practices: As you use the framework, you’ll begin to absorb the practices and (we hope) good habits of the framework’s creators.
  4. New capabilities: Frameworks regularly add functionality to help developers implement new technology. These days, common enhancements involve AJAX and connections to the APIs of popular web service providers.

Developers may understandably wonder if mastering a framework is worth the learning curve. In my opinion, the effort to learn a framework will be repaid with applications that are well-architected, flexible, and maintainable.