/ Published in: PHP
__autoload is often used to load class files from a specific user-defined directory. by simply adding the user-defined directory to the include_path, however, autoload can be used to load user class files as well as PEAR class files. Assuming the PEAR naming convention is adhered to for the user defined classes.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function __autoload($classname) { // put the path to your class files here $my_path = "/var/www/mydomain.com/lib"; // tell PHP to scan the default include paht AND your include path // name your classes and filenames with underscores, i.e., Net_Whois stored in Net_Whois.php include_once($classfile); } /** * EXAMPLE: * create one of your objects, saved in /var/www/mydomain.com/lib/Project/Database.php */ $db = new Project_Database(); /** * EXAMPLE: * create a PEAR object, saved in /usr/local/lib/php/File.php */