Helping ordinary people create extraordinary websites!
HOME TUTORIALS SCRIPTS WEB HOSTING BLOG FORUM
Get Our Newsletter
Your Email:
Webmaster Blog

Code reuse in PHP frameworks

by Akash Mehta


Code reuse: a great boon for web development. With large repositories of PHP code out there, from snippet archives to class databases, PHP is arguably one of the best languages when it comes to existing reusable code.

Of course, it isn’t nearly that simple. Everyone writes code differently; different naming conventions, different approaches to achieving common tasks (e.g. configuration), even different ways of interacting with the code (functions, classes static/non-static etc.). The problem is compounded when you start using a framework, with the intention of enforcing some basic convention - convention which your existing code libraries may not follow.

Frameworks can’t - and shouldn’t - include masses of functionality by default; an easy way to extend them with existing code is pretty important. Of all the PHP frameworks I’ve tried, CodeIgniter seems to have one of the most flexible approaches; drop a class into the libraries folder, and as long as it doesn’t need data passed through the constructor, chances are it just works. (Slight filename and class name changes might be necessary).

I’ve managed this effortlessly with an XML parsing class from phpclasses.org: in under two minutes I had added an XML parser interface that I could use just like any native CodeIgniter library.

So, how have your attempts at code reuse inside frameworks gone? I haven’t had a chance to test CakePHP yet; please comment if you’ve tried it in the past.



Tags: , , , ,


Related Posts
» Choosing a framework
» Rails vs. PHP: Fair Comparison?
» jQuery: Interaction Design for PHP Developers
» 5 essential development facts every PHP developer should know
» Benchmarking PHP frameworks
 


Leave a Reply