简体   繁体   中英

Identifying PHP unused variables

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)?

Not sure it can report unused variables, but PHP_CodeSniffe r 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 sidenote :

  • Unused variables (ie variables than get assigned a value, and are never used again) are not a problem in PHP -- so, they are not reported as error nor anything by PHP itself
  • On the other hand, undeclared variables (ie 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...

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

Netbeans IDE(我上个月从eclipse pdt换了)识别并显示有关未使用和未初始化的方法,变量等的警告。

You may be interessed in http://qualityassuranceinphpprojects.com/pages/tools.html that deals with testing/QA/CI/... and many other topics. PMD, PHP_CodeSniffer that have already been mentioned are as well in there as are many others

Install 'PDT Extensions' from here http://p2.pdt-extensions.org/

From the Eclipse(PDT) main menu select Help\\Install New Software
Then enter the above URL in the 'Work with' edit box. Click 'Add'. Check the 'PDT Extensions' checkbox. Click 'Next'...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM