PHP开发过程中的代码审查/检查方法

发布于 2024-08-18 14:19:32 字数 391 浏览 3 评论 0原文

我正在寻找在开发过程中对 PHP 代码执行健全性检查的方法,

我希望避免以艰难的方式发现编码错误,而是在发布网站之前找到它们。

display_errors = on 和类似的运行时方法发现问题为时已晚。

到目前为止,我发现了以下方法,我认为还不够彻底:

  • php_check_syntax() from inside PHP
  • php -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 PHP
  • php -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 技术交流群。

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

发布评论

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

评论(4

情何以堪。 2024-08-25 14:19:33

单元测试怎么样? =) http://www.phpunit.de/

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

才能让你更想念 2024-08-25 14:19:33

PHP 代码嗅探器可以帮助确保您按照设定的标准编写代码。

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

PHP_CodeSniffer 是一个 PHP5 脚本,用于标记和“嗅探”PHP、JavaScript 和 CSS 文件,以检测是否违反已定义的编码标准。它是一个重要的开发工具,可确保您的代码保持干净和一致。它还可以帮助防止开发人员犯的一些常见语义错误。

顺便说一句,如果您想真正进行代码检查,您可以将 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/

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.

逆光飞翔i 2024-08-25 14:19:33

你当然可以脱身一点,找个朋友、同事……或者我敢说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 :)

你与昨日 2024-08-25 14:19:33

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.

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