Backport fix for #4889 from Yii 2 repository.