yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.24k stars 6.91k forks source link

Your Exception class must extend from \Exception ; instead of extend from Exception #17973

Closed klunker closed 4 years ago

klunker commented 4 years ago

The problem with new yii\web\HttpException. In PHPShtorm showing error:

Thrown object must be an instance of 'Exception' or 'Throwable'

The problem place

OK, go step by step for extends classes and see the problem in \vendor\yiisoft\yii2\base\UserException.php

class UserException extends Exception
{
}

What steps will fix the problem?

Change Exception on \Exception



| Q                | A
| ---------------- | ---
| Yii version      | 2.0.34
| PHP version      |  7.4
| Operating system | Any
rob006 commented 4 years ago

yii\base\Exception already extends Exception: https://github.com/yiisoft/yii2/blob/master/framework/base/Exception.php#L18

klunker commented 4 years ago

Hmmm.. Something went wrong with project synchronization. And this file was not on the development server.

I started the synchronization again, the file https://github.com/yiisoft/yii2/blob/master/framework/base/Exception.php#L18 downloaded again and the error went away. Thanks you!