The type annotation of Request's "bodyParams" property states that bodyParams type is array:
https://github.com/yiisoft/yii2/blob/2.0.6/framework/web/Request.php#L35
But if content-type is application/json and request body is empty then \Yii::$app->request->bodyParams is null.
bodyParams should be an empty array if request body is empty.
Note, that there is a difference between an empty body in form of empty string and a body that contains [] or {} explicitly. However talking about bodyParams it makes sense to say if there are no params, regardless of whether the body was completely empty or explicitly, it should be an empty array...
@samdark I do not think your change fixes the issue: json_decode does not throw an exception in case of empty body: https://3v4l.org/NgSsK
We should have a test for this.
@cebe I've fixed inconsistent return type. It's not about exception.
@samdark the issue is the following:
Someone sends an HTTP request with body being an empty string: bodyParams will be null because that is what json_decode() returns. This is the case that should be catched.
Your fix seems also valid but it does not fix the issue.