Replacement for PHP's __autoload function?

Posted by Josh on Stack Overflow See other posts from Stack Overflow or by Josh
Published on 2010-04-13T14:54:51Z Indexed on 2010/04/13 15:02 UTC
Read the original article Hit count: 371

Filed under:
|
|
|

I have read about dynamically loading your class files when needed in a function like this:

function __autoload($className)
{
   include("classes/$className.class.php");
}

$obj = new DB();

Which will automatically load DB.class.php when you make a new instance of that class, but I also read in a few articles that it is bad to use this as it's a global function and any libraries that you bring into your project that have an __autoload() function will mess it up.

So does anyone know of a solution? Perhaps another way to achieve the same effect as __autoload()? Until I find a suitable solution I'll just carry on using __autoload() as it doesn't start becoming a problem until you bring in libraries and such.

Thanks.

© Stack Overflow or respective owner

Related posts about php

Related posts about autoload