1

I don't know how to work with such object, i need to get first and second one status value, tryed to convert it to json, but it gives me nothing. I just don't get it how to open array with such "_data:MailWizzApi_Params:private" name.

Source:

// SEARCH BY EMAIL
$response = $endpoint->emailSearch($myConfig["LIST-UNIQUE-ID"], $_GET["email"]);

// DISPLAY RESPONSE
echo '<hr /><pre>';
print_r($response->body);
echo '</pre>';

I receive such answer

MailWizzApi_Params Object
(
    [_data:MailWizzApi_Params:private] => Array
        (
            [status] => success
            [data] => Array
                (
                    [subscriber_uid] => an837jdexga45
                    [status] => unsubscribed
                )

        )

    [_readOnly:MailWizzApi_Params:private] => 
)
SLI
  • 713
  • 11
  • 29

2 Answers2

3

In this case, you can't.
Because it's private field.

For public fields with "incorrect" names you can use snippet:

$name = '}|{';
$obj->$name;

So, let see to your property: [_data:MailWizzApi_Params:private].

It is private field of instance of MailWizzApi_Params class with _data name.

Let's google to it's implementation: Found

As you can see it has toArray public method. Just use it.

print_r($response->body->toArray());

It has ArrayAccess implemented also. So, $response->body['status'] or $response->body['data'] will works.

vp_arth
  • 14,461
  • 4
  • 37
  • 66
0

Thank you guys for fast answers, here is my dumb way if reading status value (thanks, @Jose Manuel Abarca Rodríguez)

$toJson = json_encode((array)$response->body);
$toJson = str_replace(array("\u0000MailWizzApi_Params\u0000_"), "", $toJson);

So we receive a normal json:

{"data":{"status":"success","data":{"subscriber_uid":"an837jdexga45","status":"unsubscribed"}},"readOnly":false}

And now we need just to decode it

$json = json_decode($toJson, true);
echo $json['data']['status'];
SLI
  • 713
  • 11
  • 29