__autoload function

October 21st, 2009 § 0

Some info,snippets on PHP5 autoload function:

function __autoload($className) {
include_once __autoloadFilename($className);
}
function __autoloadFilename($className) {
return str_replace('_','/',$className).".php";
}
$class = new myclass();

When a Class is not found, php will pass the classname to the __autoload function.
You can name your class like Folder1_Folder1a_Myclass and this function will look for it in Folder1/Folder1a/Myclass.php

You can put multiple classes in one folder and still make this work by creating a link to the correct file.
On Unix, Linux machines use the command “ln -s targetfile.php nonexistingclassfile.php”

Where Am I?

You are currently browsing entries tagged with autoload exception at westworld: a webmasters best friend.