Panda PHP Components

Search

Archives

Categories

Posts Tagged ‘spl_autoload’

Autoloading with Panda_Loader_Singleton

Sunday, May 4th, 2008

I just committed a nifty update to the Panda_Loader package: Panda_Loader_Singleton. Essentially, this update just wraps the existing loader with a singleton; but don’t be fooled by the simplicity: this makes for a wicked-simple autoloading mechanism.

Implementing this component in your code is useful only when one style of code organization is used — fortunately, this is the case for most projects. The autoloader simply wraps the existing load() method — but calls it from an instance returned from a static singleton() call.

When bootstrapping your project, simply register the autoload() method and you never have to worry about including dependencies again.

spl_autoload_register(array('Panda_Loader_Singleton', 'autoload'));

Check it out yourself: http://code.google.com/p/panda-php/source/browse/trunk/Panda/Loader/Singleton.php

Panda PHP is free software distributed under the New BSD license. All content of this website is copyright © 2007 Panda PHP.