I have:

$result = $client->request('POST', 'http://'.$core_address.':'.$core_port.$core_uri, [
    'body' => json_encode([
        'a' => $a,
        'b' => $value['v'],
        'x' => $value['x'],
    'headers' => [
            'Accept' => 'application/json', 
            'Content-Type' => 'application/json'
$output = json_decode($result->getBody());

i catch the output and print it like:


problem is: if output just a flat string, it work like a charm but when it receive json like:

{'x': ['Not a valid integer.'], 't': ['Not a valid string.'], 's': ['Not a valid string.']}

192.168.yyy.xxx - - [28/Jul/2016 00:14:59] "PUT /Module HTTP/1.1" 200 -

it give me error:

Uncaught PHP Exception Exception: "Object of type stdClass cannot be printed." at /path/to/Drupal/Core/Template/TwigExtension.php line 443, referer: https://url.com/admin/core/my/module/path

why? why?

1 Answer 1


Short answer: because that is how the API was written.

Long answer is that they do not know how the object should be printed.

To cast an object to a string, you need the object to have a __toString method, which the object in question does not contain.

If you want to print the stringified version of the object then don't transform to an object using json_decode.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.