Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Load a PHP Class automatically upon instantiation (PHP5) (See related posts)

When you instantiate a class, it will try to load the file automatically.
function __autoload($class_name) {
    require_once("classes/" . $class_name . ".php");
}

Usage:
$auth = new Auth;

Will automatically load the file "classes/Auth.php"

You need to create an account or log in to post comments to this site.


Click here to browse all 5147 code snippets

Related Posts