PHP开发过程中的代码审查/检查方法
我正在寻找在开发过程中对 PHP 代码执行健全性检查的方法,
我希望避免以艰难的方式发现编码错误,而是在发布网站之前找到它们。
display_errors = on
和类似的运行时方法发现问题为时已晚。
到目前为止,我发现了以下方法,我认为还不够彻底:
php_check_syntax()
from inside PHPphp -l
from the command line- Ioncube PHP编码器
- 使用编辑器像 NetBeans 和 Eclipse 那样进行错误检查
有更多方法可以及早发现 PHP 代码中的问题吗?
I am looking for methods for performing sanity checks of PHP code during development
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 PHPphp -l
from the command line- Ioncube PHP encoder
- Using editors with error checking like NetBeans and Eclipse
Are there more ways to find problems in PHP code early?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
单元测试怎么样? =) http://www.phpunit.de/
How bout unit testing? =) http://www.phpunit.de/
PHP 代码嗅探器可以帮助确保您按照设定的标准编写代码。
http://pear.php.net/package/PHP_CodeSniffer/
顺便说一句,如果您想真正进行代码检查,您可以将 Code Sniffer、PHPUnit 和存储库与 phpUnderControl 之类的工具集成在一起,以自动执行此过程。
PHP Code Sniffer can help ensure you're writing code to a set standard.
http://pear.php.net/package/PHP_CodeSniffer/
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.
你当然可以脱身一点,找个朋友、同事……或者我敢说Coding Buddy - 没有什么比在您签入代码时让一个真人来检查您的代码更好的了:)
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 :)
DMS 软件重新工程工具包 具有完整的 PHP 解析器,可进行语法检查。如果您想要的只是语法检查,那么这是一个很大的系统。
“仅”获得 DMS 语法检查部分的一种方法是 SD PHP Formatter。该工具可以很好地格式化 PHP 代码。为此,它首先对其进行解析(进行语法检查),然后根据 PHP 语言规则隐含的结构对其进行漂亮打印。当然,您可以忽略格式化结果并仅查找解析错误。
如果您喜欢测试覆盖率的想法,您应该考虑 SD PHP 测试覆盖率工具。这会打包 DMS 来解析您的源代码,并使用检测来填充它以确定运行时执行的内容。显然,它仍然内置语法检查,并提供测试覆盖能力。
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.