views:

52

answers:

2

I have trying to solve the error : Fatal error: Cannot redeclare class

I have been looking everywhere and I can't find where the class was instantiated.

Is there anyway I can print debug info about the existing instance of that class.

+2  A: 

Chances are you are importing the file that declares the class more than once. This can be symptomatic of includes/requires getting out of control so you may need to simply your structure.

One alternative approach is to use autoload to load classes to avoid this kind of problem. Another is to only use include_once or require_once. I generally prefer to use require with a simple structure.

cletus
Php might just be getting out of control, I was already using include_once. But thanks you helped me to find where the bug was.
mnml
I was using:include_once($this->PluginDir . 'class.php');and include_once(_INCLUDE_PATH_."../class.php");somewhere else.
mnml
+1  A: 

Yes, stupid php doesn't tell you where the class was declared. Try the following (immediately before fatal error line)

$r = new ReflectionClass("YourClassName"); echo $r->getStartLine();
stereofrog
that almost looked like "Yes stupid!..."
andho