Posted By

silviud on 07/02/10


Tagged

include autoload


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

Vordreller
dantreacy


__autoload()


 / Published in: PHP
 

URL: http:://silviud.blogspot.com

  1. /*
  2. Autoload for php classes with a simple convention so you don't have to include manually files.
  3. The convention is as follow: '_' gets converted into '/' and the strings before and after '_' become
  4. directories or files.
  5. For example Process_Shell class is located under directory Process and the file name that contains
  6. the class Process_Shell is called Shell.php. The classname is Process_Process and is located into
  7. Process/Shell.php.
  8.  
  9. */
  10.  
  11. function __autoload($class){
  12. $elems = explode('_',$class);
  13. $path = implode('/',$elems);
  14. require_once($path . '.' . 'php');
  15. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: shaunduncan on July 13, 2010

Although convenient, using magic functions like __get(), __set() and __autoload() should be avoided at possible as they can hinder performance. Also, use of require_once() is very expensive.

You need to login to post a comment.