# Cannot declare class, PHP?!?

One of the most annoying errors to debug when working with a litany of autoloaders using required instead of include_once in PHP:

PHP Fatal error: Cannot declare class SomeClass, because the name is already in use in /somewhere/SomeClass.php on line 1234

What makes it annoying is the lack of a trace. You know it was only defined once, but it’s being loaded several times. To solve this quickly and find the various places it is being loaded, just wrap your class with this:

echo '*** ' . debug_backtrace()[0]['file'] . ' at line ' . debug_backtrace()[0]['line'];
if (!class_exists('SomeClass')) {
class SomeClass
{
...
}
}