News Feed
Sections




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

Mike Naberezny's Blog:
__get() - an alternative to __autoload()
January 09, 2008 @ 06:47:54

Mike Naberezny has posted this new item on his blog today with a look at why __get() is a perfectly good alternative to __autoload() in a class structure.

__autoload() is a magic function introduced in PHP 5 that provides a mechanism for on-demand loading of classes. After its inclusion in PHP, many argued that using such a feature is too magical or not a good design practice. Putting the religious debates over the appropriateness of __autoload() aside, its implementation does have one significant drawback: it is a function declared in the global scope. Once a function is declared, it cannot be redeclared. This means __autoload() can't be used effectively in shared libraries, since any other code could have already declared it.

Similar lazy-load functionality can be achieved on the class level by using __get().

He gives a short code example where the __get() call mimics the functionality of __autoload(), but the resulting object created is public, not global...

0 comments voice your opinion now!
__get __autoload alternative global versus public __get __autoload alternative global versus public


blog comments powered by Disqus

Similar Posts

Fabien Potencier: The PHP Security Advisories Database

Federico Cargnelutti's Blog: An Alternative to Zend_Controller: The Router

Vance Lucas' Blog: Get Only Public Class Properties for the Current Class in PHP

Greg Beaver's Blog: phpDocumentor and __get/__set/__call - give us your ideas (RFC)

Soledad Penades' Blog: Signs your PHP needs refactoring


Community Events

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


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

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