如何调试 PHP 中的类重定义?

发布于 2024-11-14 05:55:10 字数 349 浏览 6 评论 0原文

我收到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

百变从容 2024-11-21 05:55:10

在声明类的文件中但在声明之前使用 debug_backtrace

Use debug_backtrace in file where is class declared, but before it's declaration

万劫不复 2024-11-21 05:55:10

另一种方法是重命名重新定义的类(也重命名包含该类的文件),然后修复由此产生的所有类未找到错误。这应该会引导您找到导致重新定义的代码。就我而言,是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文