News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Ian Selby's Blog:
Dynamically Add Functions to PHP Classes
January 05, 2009 @ 10:26:50

Ian Selby has posted a new tutorial today looking at something that can be very handy in the right situations - dynamically adding new functions to an already defined PHP class.

I've gotten a lot of great suggestions for features [for PHP Thumbnailer], and have wanted to add them, but at the same time don't as I would prefer not to bloat the class with all sorts of functionality. So I started thinking about how I could provide certain functionality for people that want it, without either simply making it a part of the class (and making it more bloated as a result), or coming up with all sorts of extended classes to maintain and distribute.

His solution was to add functionality dynamically to the class as plugins. Each plugin is defined as its own class (to keep things standardized) and will be included/executed by a base controller class. He includes some sample code showing how to create a basic user object that can store the first and last names of the user in question.

0 comments voice your opinion now!
dynamic add function method class plugin tutorial user


blog comments powered by Disqus

Similar Posts

Zend Developer Zone: Avoiding XSS security attacks to sites that use HTML editors

PHPBuilder.com: AJAX and PHP Part 2 - XML Communication/Processing

IBM developerWorks: Intro to MVC Programming with Agavi, Part 1: Open a whole new world with Agavi

WebReferece.com: Managing Your Email Campaigns with phpList

NETTUTS.com: The Problem with PHP’s Prepared Statements


Community Events





Don't see your event here?
Let us know!


install podcast voicesoftheelephpant language interview library bugfix package series symfony release laravel introduction list framework tips deployment api opinion community

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework