PHP Sanity Check

好久不见. 提交于 2020-02-21 06:13:46

问题


I am looking for applications or methods for performing sanity checks of php code. I hope to to avoid finding out about the coding mistakes the hard way, but instead find them before publishing the website.

display_errors = on and similar run-time methods find the problems too late.

So far I have found the following ways, which I think are not thorough enough:

  • php_check_syntax() from within php
  • php -l from the command line
  • ioncube php encoder
  • netbeans and eclipse as editors

What better way is there to find problems in PHP code early?


回答1:


PHP Code Sniffer can help ensure you're writing code to a set standard.

http://pear.php.net/package/PHP_CodeSniffer/

PHP_CodeSniffer is a PHP5 script that tokenises and "sniffs" PHP, JavaScript and CSS files to detect violations of a defined coding standard. It is an essential development tool that ensures your code remains clean and consistent. It can also help prevent some common semantic errors made by developers.

Incidentally, if you want to get really into code checking, you can integrate Code Sniffer, PHPUnit and a repo together with something like phpUnderControl for automating such a process.




回答2:


How bout unit testing? =) http://www.phpunit.de/




回答3:


You could of course strip back a little and get a friend, colleague ... or dare I say it a Coding Buddy - nothing better than getting a real human being to check your code when you check it in :)




回答4:


The DMS Software Reengineering Toolkit has a full PHP parser which does syntax checks. That's a big system if all you want is syntax checking.

One way to get "just" the syntax checking part of DMS is the SD PHP Formatter. This tool formats PHP code nicely. To do so, it parses it first (there's the syntax check) and then prettyprints it according to the structures implied by the PHP language rules. Of course, you could just ignore the formatted result and simply look for parsing errors.

If you like the test coverage idea, you should consider the SD PHP Test Coverage tool. This packages DMS to parse your source code, fill it with instrumentation to determine what gets executed when you run. It obviously has the syntax check still built in, as well as providing the test coverage ability.



来源:https://stackoverflow.com/questions/2097037/php-sanity-check

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!