开发者

Identifying PHP unused variables

开发者 https://www.devze.com 2023-01-07 11:24 出处:网络
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

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 vari开发者_如何学Pythonables (in Emacs)?


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:
    • displayed in the generated page (nice when developping) : display_errors
    • or logged in a file: log_errors

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...


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


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


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...

0

精彩评论

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

关注公众号