2017-12-18 19:44:37 9371次浏览 4条回答 0 悬赏 30 金钱

phpStorm近期升级后,新增了些新的功能,导致打开项目后,有些会有异常提示甚至报错:
情况一:
Unhandled \yii\web\NotFoundHttpException less... (Ctrl+F1 Alt+T) The inspection reports exceptions which are neither enclosed in a try-catch block nor documented using the '@throws' tag
如图:
企业微信截图_15135967806916.png

看官网上更新说明是这样的:
企业微信截图_1513596848842.png

这种写法有问题吗?
我是自己重写了findModel方法:

/**
     * Finds the OrderMain model based on its primary key value.
     * If the model is not found, a 404 HTTP exception will be thrown.
     * @param integer $id
     * @return OrderMain the loaded model
     * @throws NotFoundHttpException if the model cannot be found
     */
    protected function findModel($id)
    {
        if (($model = OrderMain::findOne($id)) !== null) {
            return $model;
        } else {
            throw new NotFoundHttpException('The requested page does not exist.');
        }
    }

情况二:
Arbitrary expressions in empty are allowed in PHP 5.5 only less... (Ctrl+F1 Alt+T) Checks that language features used in the source code correspond the selected language level. (i.e. traits can be used only in PHP 5.4)

企业微信截图_15135972702537.png

情况三:
TIM截图20171218194206.png

这种形式我一直在用,而且现在也不会报错,只是在编辑器的时候就会报错

补充于 2017-12-20 09:18

企业微信截图_15137326676916.png

最佳答案

  • 回答于 2017-12-19 21:01 举报

    function前面的 /* 加上'@throws'标签

    1 条回复
    回复于 2017-12-20 09:17 回复

    OK,谢谢,您说的这个我加上之后,方法里面的都OK了,但是view中还是这个,图片见补充问题

  • 回答于 2018-01-15 10:55 举报

    关闭phpstorm错误提示

  • 回答于 2018-03-27 11:21 举报

    /**

     * Make one feild rule
     *
     * @param object $field
     * @return array|string
     * @throws Exception
     */
     
     方法注释里面加 @throws Exception 就解决
    
您需要登录后才可以回答。登录 | 立即注册
Steven0T
总监

Steven0T 上海

注册时间:2017-09-22
最后登录:2023-07-17
在线时长:28小时32分
  • 粉丝10
  • 金钱2970
  • 威望160
  • 积分4850

热门问题