如何调试 PHP 中的类重定义?
我收到 PHP Fatal error: Cannot redeclare class Foo in /directory/ on line 20
错误,但我不知道它来自哪里。我总是对此类文件使用 require_once
,但我不知道如何调试它。我可以以某种方式获得某种包含堆栈跟踪吗?我正在运行 PHP 5,因此此处描述的区分大小写应该不是问题: http://www.php.net/manual/en/function.include-once.php。
I'm getting a PHP Fatal error: Cannot redeclare class Foo in /directory/ on line 20
error, but I have no idea where it's coming from. I'm always using require_once
for this class file, and I'm not sure how to debug it. Can I get some kind of inclusion stack trace somehow? I'm running PHP 5, so case sensitivity such as descriped here should not be a problem: http://www.php.net/manual/en/function.include-once.php.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在声明类的文件中但在声明之前使用 debug_backtrace
Use debug_backtrace in file where is class declared, but before it's declaration
另一种方法是重命名重新定义的类(也重命名包含该类的文件),然后修复由此产生的所有类未找到错误。这应该会引导您找到导致重新定义的代码。就我而言,是 class_alias 语句导致了问题。
Another approach is to rename the class that was redefined (also rename the file containing the class) and then fix all class-not-found errors you get from that. That should lead you to the code that is causing the redefinition. In my case it was a class_alias statement that was causing the problem.