开发者

Find where a class was instantiated

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.


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.


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();


You can find out, where an object was instantiated by using var_dump(debug_backtrace()); and looking at the call stack.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜