News Feed
Sections




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

Chris Cassell's Blog:
Creating Magic Methods in PHP
August 13, 2007 @ 10:21:00

In this new entry to his blog today, Chris Cassell shows how to create "magic methods" - ones that make use of overloading to do special things.

I've learned a lot of things from various open source frameworks, especially CakePHP. One of the most impressive things about Cake, and Ruby on Rails for that matter, is its magic methods in its data model class [...] I've implemented similar methods in the home-grown framework that I use at work. Here's how to do it.

In his example, he gives both the PHP4 and PHP5 code to make a simple magic method class with a __call() function to handle undefined method calls. Using this, he maps a undefined method call to another method in the class (called findAllByColor and mapped to findAll with the right parameters).

1 comment voice your opinion now!
tutorial magic method class php5 php4 cakephp framework tutorial magic method class php5 php4 cakephp framework


blog comments powered by Disqus

Similar Posts

PHPBuilder.com: BitMasks: Emulate Unix Permissions in PHP (Quickly)

Manuel Pichler's Blog: PHP_Depend jumps on the D-BUS

Dan Scott's Blog: Creating a MARC record from scratch in PHP using File_MARC

Pablo Viquez's Blog: Zend_Log, FirePHP and Zend_Application. How to

SitePoint PHP Blog: Create a Movie Recommendation App with Prediction.io - Setup


Community Events

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


security opinion laravel5 extension community unittest version framework symfony library interview release voicesoftheelephpant language laravel series introduction api threedevsandamaybe podcast

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