You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If in the exception stack trace a function argument contains binary data that json_encode could not handle, then json_encode will return false. As a result the response content is empty.
This situation can occur in various debugging scenarios, e.g. uploading a file and passing its blob to a function, and it can be pretty difficult to overcome because the empty response.
Proposed solution
A better choice would be to use \Zend\Json\Encoder::encode because it can correctly handle the encoding of binary data that json_encode can not encode.
// Assuming $data['blob'] contains the binary data of a PDF filejson_encode($data); // return false
\Zend\Json\Json::encode($data); // return false if the json extension is available, otherwise \Zend\Json\Encoder::encode is used
\Zend\Json\Encoder::encode($data); // return the encoded json
Assume
displayExceptions
istrue
.If in the exception stack trace a function argument contains binary data that
json_encode
could not handle, thenjson_encode
will returnfalse
. As a result the response content is empty.This happens at following lines:
RenderErrorListener.php#L94
ApiProblemResponse.php#L59
This situation can occur in various debugging scenarios, e.g. uploading a file and passing its blob to a function, and it can be pretty difficult to overcome because the empty response.
Proposed solution
A better choice would be to use
\Zend\Json\Encoder::encode
because it can correctly handle the encoding of binary data thatjson_encode
can not encode.Originally posted by @leogr at zfcampus/zf-api-problem#29
The text was updated successfully, but these errors were encountered: