porting the fix from https://github.com/yiisoft/yii/pull/2894