[horde] Converting stdClass object trees to arrays?

Adam Tauno Williams awilliam at whitemice.org
Mon Apr 25 19:25:14 UTC 2011


On Mon, 2011-04-25 at 14:43 -0400, Michael J Rubinsky wrote:
> Adam Tauno Williams <awilliam at whitemice.org> wrote:
> >I'm updating our Auth and Group providers for the latest Horde release.
> >These communicate with our backend server using JSON-RPC 1.1.  So I'm
> >using the Horde_Rpc_Jsonrpc::request class/method.  That part is
> >working
> >very well [switching from XML-RPC which we used previously].  
> >In $response->result is the results of the JSON-RPC call. But these are
> >stdClass object trees, not 'arrays'.  So in some pages I get errors
> >like
> >-
> >PHP Fatal error:  Cannot use object of type stdClass as array
> >in /srv/www/htdocs/horde/templates/admin/groups/edit.inc on line 7
> >Is the a standard / horde-ish way to convert the deserialized responses
> >to arrays?
> Just cast the stdClass to an array.

Yep, that works for single-level data structures like the list of users
for a group.  But [obviously] the cast does not recurse so other
structures need to have all their child keys cast as well.  It just
seems awkward.

    public function getData($gid)
    {
        $response = $this->_server->request('group.getdata',
array($gid));
        $data = array();
        $data['name']  = $response->result->name;
        $data['email'] = $response->result->email;
        $data['users'] = (array) $response->result->users;
        return $data;
    }




More information about the horde mailing list