识别 PHP 未使用的变量

发布于 2024-09-09 21:25:53 字数 334 浏览 0 评论 0原文

我看到了下面的问题,想知道 Eclipse 是否有类似的东西

另外,我如何确保这种错误被抛出到我的触发错误函数中,以便我可以将其写入日志。

如何识别 PHP 未使用的变量(在 Emacs 中)?< /em>

I have seen the below question and was wondering if there is something like it for Eclipse.

Also, how can I make sure that this kind of errors gets thrown into my trigger error function, so that I can write it to a log.

How can I identify PHP unused variables (in Emacs)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

脸赞 2024-09-16 21:25:54

不确定它是否可以报告未使用的变量,但是 PHP_CodeSniffer 很好用用于检测 PHP 源代码中的问题。

尽管如此,它仍然是一个命令行工具,并且没有集成在 Eclipse PDT 中...

As a side note:

  • 未使用的变量(即,分配了值,并且不再使用的变量) 在 PHP 中不是问题-- 因此,PHP 本身不会将它们报告为错误或任何内容。
  • 另一方面,未声明的变量(即正在读取的变量,但之前没有为其赋值)不太好——因此,PHP 引擎会向它们报告一条通知。

您链接到的帖子讨论的是第二种,而不是第一种。

To get undeclared/uninitialized variables reported by the PHP engine:

  • 您必须启用 error_reporting< /code>,并对其进行配置,使其报告 E_NOTICE
  • 然后,您可以通过以下任一方式获取这些报告:

但是,这里也没有集成在 Eclipse 中——我从未见过一个可以解析 PHP 错误日志并将通知推送到 Eclipse 的工具...

Not sure it can report unused variables, but PHP_CodeSniffer is nice when it comes to detecting problems in PHP source code.

Still, it's a command-line tool, and it's not integrated in Eclipse PDT...

As a side note:

  • Unused variables (i.e., variables that get assigned a value, and are never used again) are not a problem in PHP -- so, they are not reported as an error nor anything by PHP itself
  • On the other hand, undeclared variables (i.e., variables that are being read from, while no value was assigned to them before) are not that good -- so, they are reported a notices by the PHP engine.

The post you are linking to is talking about the second kind, and not the first one.

To get undeclared/uninitialized variables reported by the PHP engine:

  • You have to enable error_reporting, and configure it so it report E_NOTICE
  • You can then have those reports either:

But, here too, this is not integrated in Eclipse -- and I've never seen a tool that would parse the PHP error log, and push the notices to Eclipse...

别低头,皇冠会掉 2024-09-16 21:25:54

NetBeans IDE(我从 Eclipse PDT 上个月)识别并显示有关未使用和未初始化的方法、变量等的警告。

The NetBeans IDE (I switched from Eclipse PDT last month) identifies and shows warning about unused and uninitialized methods, variables, etc.

心凉 2024-09-16 21:25:54

您尝试过 PMD Eclipse 吗?
据我的同事说,这是一个非常方便的工具。

Have you tried PMD Eclipse yet?
According to my colleagues it is a pretty handy tool.

好倦 2024-09-16 21:25:54

安装 PDT 扩展

从 Eclipse (PDT) 主菜单中,选择帮助 → < em>安装新软件。

然后在“使用”编辑框中输入上述 URL。单击添加。选中“PDT 扩展”复选框。单击下一步...

Install PDT Extensions.

From the Eclipse (PDT) main menu, select HelpInstall New Software.

Then enter the above URL in the 'Work with' edit box. Click Add. Check the 'PDT Extensions' checkbox. Click Next...

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