News Feed
Sections




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

Stubbles Blog:
Extending objects with new methods at runtime
September 01, 2009 @ 09:05:46

On the Stubbles blog today Frank Kleine looks at a cool trick that the features of PHP 5.3 now make possible - extending objects at runtime by adding in new methods and functionality.

With the advent of PHP 5.3 adding new methods to an instance of a class at runtime becomes possible with PHP as well, using anonymous functions and a little bit of __call() magic.

He illustrates with a bit of code - defining the base class and using a __call method to catch any undefined method calls. Using this in conjunction with closures makes it possible to call the method internally, avoiding the usual error that could result from setting it like you would a class property.

0 comments voice your opinion now!
extend object closure call


blog comments powered by Disqus

Similar Posts

Jacob Santos' Blog: Patterns for PHP: Page Controller Draft

DevShed: Overloading and Object-Oriented Programming with PHP 5

Brandon Savage's Blog: Five Tips To Make Good Object-Oriented Code Better

David Goodwin's Blog: Storing PHP objects in a database (please no!)

Gergely Hodicska's Blog: Extending Zend_Acl to support custom roles and resources


Community Events

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


php7 release laravel community xdebug api example introduction library performance opinion conference interview voicesoftheelephpant symfony2 framework extension series version podcast

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