SLI SLI - 6 months ago 9
PHP Question

How to work with not standart named array in object

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] =>
)

Answer

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.