开发者

Find where a class was instantiated

开发者 https://www.devze.com 2022-12-09 16:24 出处:网络
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.

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

精彩评论

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