PHPLint似乎是答案。例如,它解析
<?php
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.
所以这正是我所要求的:) 添加一个 docblock 并捕获异常不会导致 PHPLint 出现更多错误或警告。