php静态检测工具,PHP静态代码分析工具,可以检测未捕获的异常?
PHPLint似乎就是答案.例如,它解析
function some()
{
if (time() == 123) {
throw new Exception("I can't happen");
}
}
some();
,永远不会抛出异常(除非你过去),进入:
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不再出现错误或警告.