PHP静态代码分析工具,可检测未捕获的异常? [英] PHP static code analysis tool, which detects uncaught exceptions?

查看:64
本文介绍了PHP静态代码分析工具,可检测未捕获的异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎有很多用于PHP的静态代码分析工具,您能否建议一个可以检测PHP代码中抛出但从未发现的异常的工具? (从理论上讲,这可以停止在PHP脚本上的执行).

There seems to be quite a lot of static code analysis tools for PHP, could you please suggest the one, which can detect exceptions, which are thrown in the PHP code, but are never caught? (the ones, which can theoretically stop the execution on the PHP script).

我很高兴只看到像throw new SomeException()这样的东西,其中SomeException扩展了Exception.

I would be happy enough to see only stuff like throw new SomeException(), where SomeException extends Exception.

我不是在寻找过于复杂的东西-只是警告我,如果我从index.php运行someFunctionThatCanThrow(因为里面有throw语句)(你明白了),我可能会遇到麻烦.即使在运行时也永远不会发生.

I am not looking for something too sophisticated - just to warn me that if I run someFunctionThatCanThrow ('cause there is throw statement inside) from index.php (you get the point), I can get in trouble. Even if in the runtime that would never happen.

谢谢.

推荐答案

PHPLint 似乎是答案.例如,它解析

PHPLint seems to be the answer. For example, it parses

<?php

function some()
{
    if (time() == 123) {
        throw new Exception("I can't happen");
    }
}

some();

,它将永远不会引发异常(除非您过去),进入:

, which will never throw an exception (unless you're in the past), into:

BEGIN parsing of test-cSdHoW
1:      <?php
2:      
3:      function some()
4:      {
5:       if (time() == 123) {
6:        throw new Exception("I can't happen");

          throw new Exception("I can't happen");
                                                \_ HERE
==== 6: notice: here generating exception(s) Exception

          throw new Exception("I can't happen");
                                                \_ HERE
==== 6: ERROR: exception(s) must be caught or declared to be thrown: Exception
7:       }
8:      }
9:      
10:     some();
==== 3: notice: guessed signature of the function `some()' as void()

        some();
             \_ HERE
==== 10: notice: here generating exception(s) Exception

        some();
             \_ HERE
==== 10: Warning: uncaught exception(s): Exception
END parsing of test-cSdHoW
==== ?: notice: unused package `dummy.php'
==== ?: notice: required module `standard'
Overall test results: 1 errors, 1 warnings.

这正是我要的内容:)添加文档块并捕获异常不会导致来自PHPLint的更多错误或警告.

So that's exactly what I was asking for :) Adding a docblock and catching the exception results in no more errors or warnings from PHPLint.

这篇关于PHP静态代码分析工具,可检测未捕获的异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆