Yii::$app->user->isGuest for some reason checks findIdentity()

In yii2 advanced app I have action with guest check:




public function actionLogin()

 {

        if (!Yii::$app->user->isGuest)

        ...

 }



I have modified findIdentity($id) in common/models/User from this:




public static function findIdentity($id)

{

        return static::findOne(['id' => $id]);

}



to this:




public static function findIdentity($id)

    {

        if (($model = static::findOne(['id' => $id])) !== null) {

            return $model;

        } else {

            throw new UserException('User not found');

        }

    }



now, if user is deleted and he is logged in (has session), message ‘User not found’ appears every time, I can not even /logout.

so, how to fix/mofidy isGuest() function? I have a lot of actions on my website that use findIdentity($id) and it is hard to modify them all to check whether user is nulled or not.

Just log out user after deletion.

How to do that? I have found only http://stackoverflow.com/questions/32734148/yii2-logout-from-all-browser-after-a-user-change-password, but there is a problem with finding old session id. Maybe there is another way?

PHP interfaces cannot enforce return types but the documentation is clear: