__autoload() problem?
Posted: Fri Sep 24, 2010 12:54 pm
I've having a little trouble with the __autoload() function. It's best explained with an example:
Expected (/application/models/MySQLiConnection.php does NOT exist):
Unexpected (/application/models/MySQLiConnection.php does NOT exist):
As a comparison, if the file DOES exist then __autoload() works fine both when calling a class using the constructor and when calling using a static method. Is this a bug, or is this explicable behaviour?
Expected (/application/models/MySQLiConnection.php does NOT exist):
Code: Select all
function __autoload($class) {
if (!include('/application/models/' . $class . '.php')) {
throw new Exception('Unable to call ' . $class);
}
}
try {
$one = new MySQLiConnection();
}
catch (Exception $e) {
echo $e->getMessage();
}
// Outputs: "Unable to call MySQLiConnection."
Code: Select all
function __autoload($class) {
if (!include('/application/models/' . $class . '.php')) {
throw new Exception('Unable to call ' . $class);
}
}
try {
$one = MySQLiConnection::SetConnection();
}
catch (Exception $e) {
echo $e->getMessage();
}
// Outputs: "Fatal error: Class 'MySQLiConnection' not found in C:\Users\Michael\Websites\index.php on line 12."