How php handles an object and gets the value of the object element, below is object?

I want to get the value of body, what to do

object(HttpResponse)-sharp11 (7) {
  ["content":"HttpResponse":private] => string(1047) "HTTP/1.1 200 OK
Server: Tengine
Date: Fri, 22 Jun 2018 09:52:33 GMT
Content-Type: application/json; charset=UTF-8
Content-Length: 52
Connection: keep-alive
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET,POST,PUT,DELETE,HEAD,OPTIONS,PATCH
Access-Control-Allow-Headers: X-Requested-With,X-Sequence,X-Ca-Key,X-Ca-Secret,X-Ca-Version,X-Ca-Timestamp,X-Ca-Nonce,X-Ca-API-Key,X-Ca-Stage,X-Ca-Client-DeviceId,X-Ca-Client-AppId,X-Ca-Signature,X-Ca-Signature-Headers,X-Ca-Signature-Method,X-Forwarded-For,X-Ca-Date,X-Ca-Request-Mode,Authorization,Content-Type,Accept,Accept-Ranges,Cache-Control,Range,Content-MD5
Access-Control-Max-Age: 172800
X-Ca-Request-Id: CC7C80AD-3CCB-4F54-B14D-3BDA143AC3BE
Vary: Accept-Encoding
ufe-result: A2
Pragma: no-cache
Cache-Control: no-store
Via: 71aae546d43b[web,200]
Set-Cookie: SERVERID=c0cb0a9f805e8a70fc370b48877e9e8e|1529661153|1529661153;Path=/
X-Ca-Error-Message: OK
X-Ca-Debug-Info: {"TotalLatency":81,"ServiceLatency":55}

{"code":601,"message":"","data":null}"
  ["body":"HttpResponse":private] => string(52) "{"code":601,"message":"","data":null}"
  ["header":"HttpResponse":private] => string(995) "HTTP/1.1 200 OK
Server: Tengine
Date: Fri, 22 Jun 2018 09:52:33 GMT
Content-Type: application/json; charset=UTF-8
Content-Length: 52
Connection: keep-alive
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET,POST,PUT,DELETE,HEAD,OPTIONS,PATCH
Access-Control-Allow-Headers: X-Requested-With,X-Sequence,X-Ca-Key,X-Ca-Secret,X-Ca-Version,X-Ca-Timestamp,X-Ca-Nonce,X-Ca-API-Key,X-Ca-Stage,X-Ca-Client-DeviceId,X-Ca-Client-AppId,X-Ca-Signature,X-Ca-Signature-Headers,X-Ca-Signature-Method,X-Forwarded-For,X-Ca-Date,X-Ca-Request-Mode,Authorization,Content-Type,Accept,Accept-Ranges,Cache-Control,Range,Content-MD5
Access-Control-Max-Age: 172800
X-Ca-Request-Id: CC7C80AD-3CCB-4F54-B14D-3BDA143AC3BE
Vary: Accept-Encoding
ufe-result: A2
Pragma: no-cache
Cache-Control: no-store
Via: 71aae546d43b[web,200]
Set-Cookie: SERVERID=c0cb0a9f805e8a70fc370b48877e9e8e|1529661153|1529661153;Path=/
X-Ca-Error-Message: OK
X-Ca-Debug-Info: {"TotalLatency":81,"ServiceLatency":55}

"
  ["requestId":"HttpResponse":private] => string(36) "CC7C80AD-3CCB-4F54-B14D-3BDA143AC3BE"
  ["errorMessage":"HttpResponse":private] => string(2) "OK"
  ["contentType":"HttpResponse":private] => string(31) "application/json; charset=UTF-8"
  ["httpStatusCode":"HttpResponse":private] => int(200)
}
Php
Mar.23,2021

this problem can be dealt with by converting a reflection function into an array

$ref = new ReflectionClass($response);
        $props = $ref->getProperties();
        $arr = [];


        foreach ($props as $prop) {
            $prop->setAccessible(true);
            $arr[$prop->getName()] = $prop->getValue($response);
            $prop->setAccessible(false);
        }

you can get such an array, and the problem is solved

array(7) {
  ["content"] => string(1048) "HTTP/1.1 200 OK
Server: Tengine
Date: Mon, 25 Jun 2018 02:22:15 GMT
Content-Type: application/json; charset=UTF-8
Content-Length: 52
Connection: keep-alive
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET,POST,PUT,DELETE,HEAD,OPTIONS,PATCH
Access-Control-Allow-Headers: X-Requested-With,X-Sequence,X-Ca-Key,X-Ca-Secret,X-Ca-Version,X-Ca-Timestamp,X-Ca-Nonce,X-Ca-API-Key,X-Ca-Stage,X-Ca-Client-DeviceId,X-Ca-Client-AppId,X-Ca-Signature,X-Ca-Signature-Headers,X-Ca-Signature-Method,X-Forwarded-For,X-Ca-Date,X-Ca-Request-Mode,Authorization,Content-Type,Accept,Accept-Ranges,Cache-Control,Range,Content-MD5
Access-Control-Max-Age: 172800
X-Ca-Request-Id: 271C3605-1937-4FF4-8D9B-D8E0F530875C
Cache-Control: no-store
X-Ca-Error-Message: OK
Vary: Accept-Encoding
ufe-result: A2
Pragma: no-cache
Via: 71aae546d43b[web,200]
Set-Cookie: SERVERID=c0cb0a9f805e8a70fc370b48877e9e8e|1529893335|1529893335;Path=/
X-Ca-Debug-Info: {"TotalLatency":105,"ServiceLatency":56}

{"code":601,"message":"","data":null}"
  ["body"] => string(52) "{"code":601,"message":"","data":null}"
  ["header"] => string(996) "HTTP/1.1 200 OK
Server: Tengine
Date: Mon, 25 Jun 2018 02:22:15 GMT
Content-Type: application/json; charset=UTF-8
Content-Length: 52
Connection: keep-alive
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET,POST,PUT,DELETE,HEAD,OPTIONS,PATCH
Access-Control-Allow-Headers: X-Requested-With,X-Sequence,X-Ca-Key,X-Ca-Secret,X-Ca-Version,X-Ca-Timestamp,X-Ca-Nonce,X-Ca-API-Key,X-Ca-Stage,X-Ca-Client-DeviceId,X-Ca-Client-AppId,X-Ca-Signature,X-Ca-Signature-Headers,X-Ca-Signature-Method,X-Forwarded-For,X-Ca-Date,X-Ca-Request-Mode,Authorization,Content-Type,Accept,Accept-Ranges,Cache-Control,Range,Content-MD5
Access-Control-Max-Age: 172800
X-Ca-Request-Id: 271C3605-1937-4FF4-8D9B-D8E0F530875C
Cache-Control: no-store
X-Ca-Error-Message: OK
Vary: Accept-Encoding
ufe-result: A2
Pragma: no-cache
Via: 71aae546d43b[web,200]
Set-Cookie: SERVERID=c0cb0a9f805e8a70fc370b48877e9e8e|1529893335|1529893335;Path=/
X-Ca-Debug-Info: {"TotalLatency":105,"ServiceLatency":56}

"
  ["requestId"] => string(36) "271C3605-1937-4FF4-8D9B-D8E0F530875C"
  ["errorMessage"] => string(2) "OK"
  ["contentType"] => string(31) "application/json; charset=UTF-8"
  ["httpStatusCode"] => int(200)
}

convert objects into arrays


$object- > body try


get_object_vars can convert objects into arrays


add

to HttpResponse
public function getBody()
{
    return $this->body;
}

Thank you for the invitation.

regardless of whether there are sub-objects in the object or not, you can use the following methods to fix

//
$arr=json_decode(json_encode($obj),true);

you can easily access the elements in the object through an array.

refer to black technology of php object rotation array
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e4fc40-4505d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e4fc40-4505d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?