News Feed
Sections




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

PHPMaster.com:
Autoloading in PHP and the PSR-0 Standard
February 13, 2012 @ 12:29:24

On PHPMaster.com today there's a new tutorial introducing you to the PSR-0 standard and how it effects the autoloading in many PHP applications and frameworks. Specifically, they show how it's implemented in a Symfony2 component

In this article I'll walk you through the "history of autoloading," from the older to the current PSR-0 standard autoloader approach found in many PHP frameworks such as Lithium, Symfony, Zend, etc. Then I will introduce you to the ClassLoader component from the Symfony2 project for PHP 5.3 which follows the PSR-0 standard.

He starts with a look at a basic "__autoload" function call that looks in a directory for libraries. Improving on that, he makes two methods for loading - one for controllers, the other for models - and a loader that splits on the "_" character and determines the path from there.

Even this isn't PSR-0, though, so he shows how using namespace information, you can load classes in a unified way. He shows how to implement this with a loader that's already well-developed and ready for use - the Symfony ClassLoader component. They show how to register namespaces, prefixes as well as use the APC functionality to manually store/fetch the APC version of the loaded file's opcodes.

0 comments voice your opinion now!
autoload psr0 standard namespace symfony2 classloader tutorial


blog comments powered by Disqus

Similar Posts

Wojciech Sznapka's Blog: Loosening dependencies with closures in PHP

Jan Lehnardt's Blog: Using the Zend Framework with Code Igniter (an alternative)

Symfony Blog: The new Getting Started tutorial

Zend Developer Zone: PHP and Java: Using Java Print Service with Zend Server Community Edition

PHPBuilder.com: Back to Basics: Managing PHP Configuration php.ini Directives


Community Events

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


interview unittest extension php7 language laravel5 framework series laravel example library voicesoftheelephpant podcast opinion conference introduction community version api release

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