davidtsadler / ebay-sdk-php

An eBay SDK for PHP. Use the eBay API in your PHP projects.
Apache License 2.0
350 stars 343 forks source link

Is it possible to convert types to an anonymous object? #136

Closed ChangePlaces closed 7 years ago

ChangePlaces commented 7 years ago

I'd like to store the category hierarchy in the database, but instead of serializing specific objects from this library, I'd like to json encode them without having to manually extracting the properties individually into an array, e.g. (pseudo code):

$arr = [];
foreach ($response->CategoryArray->Category as $c)
{
    $obj->y = $obj->y
    $obj->x = $c->x
    $arr[] = $obj;
}

I'd like some way to just get the category array as objects which can then be json_encode'd and shoved into the db.

Is this possible, or is manual parsing the only solution?

ChangePlaces commented 7 years ago

There's a toArray method in the base type:


$arr = [];
foreach ($response->CategoryArray->Category as $c)
    $arr[] = $c->toArray();

json_encode($arr);

thanks - this sdk just gets better :)