I have a strange issue. I have a static method that loads classes (load_library). When it loads a particular class, it gives me a "cannot redeclare class" fatal error, but when testing whether the class exists right before using the load_library method to load it, it says the class does not exist. The load_library
method works elsewhere without such errors.
If I take the load_library call out, it says it cannot find the class when the class is actually used a few lines later. Stranger still, if I take out my registered class autoload
function instead, everything works perfectly, even though this autoload
function doesn't even check the directory that the class I'm trying to load is in.
It's a complicated problem involving many files so it is hard to post code, but does this problem smell familiar to anyone out there?
My load_library method:
public static function load_library($name) {
if (!class_exists($name)) {
if (file_exists('application/libraries/' . $name . '.php')) {
include('application/libraries/' . $name . '.php');
} else {
trigger_error('Request made for non-existant library ('.$name.').', E_USER_ERROR);
}
}
}
My call to the load_library method:
lev::load_library('lev_unit_tester/lev_base_test');
My registered autoload method:
public static function autoloader($name) {
if (class_exists($name)) return;
if (file_exists('application/libraries/' . $name . '.php')) {
include('application/libraries/' . $name . '.php');
}
}
The class I am trying to load (this is where the error occurs):
abstract class lev_base_test {
}
The actual error message:
Fatal error: Cannot redeclare class lev_base_test in /some/path/application/libraries/lev_unit_tester/lev_base_test.php on line 5