MDL-37355 object are automatically cast into object by the return value

This commit is contained in:
Jerome Mouneyrac 2013-01-07 11:11:14 +08:00
parent 9da506c2a3
commit 9a4c2f50c9
2 changed files with 69 additions and 2 deletions

View file

@ -266,10 +266,16 @@ class external_api {
}
} else if ($description instanceof external_single_structure) {
if (!is_array($response)) {
throw new invalid_response_exception('Only arrays accepted. The bad value is: \'' .
if (!is_array($response) && !is_object($response)) {
throw new invalid_response_exception('Only arrays/objects accepted. The bad value is: \'' .
print_r($response, true) . '\'');
}
// Cast objects into arrays.
if (is_object($response)) {
$response = (array) $response;
}
$result = array();
foreach ($description->keys as $key=>$subdesc) {
if (!array_key_exists($key, $response)) {