N1ghteyes

Active Member
Mar 3, 2014
33
2
8
Reading, UK
cPanel Access Level
Root Administrator
Twitter
Hi Guys,

Im pretty sure im having a slow day but i cant for the life of me seem to get the data out of the responce object.

PHP:
print "<pre>";
print_r($xmlapi->accountsummary('username'));
print "</pre>";
spits out something like this:

Code:
SimpleXMLElement Object
(
    [acct] => SimpleXMLElement Object
        (
            [backup] => 0
            [disklimit] => 2000M
            [diskused] => 372M
            [domain] => ***
            [email] => ***
            [ip] => ***
            [is_locked] => 0
            [legacy_backup] => 1
            [max_defer_fail_percentage] => unlimited
            [max_email_per_hour] => unlimited
            [maxaddons] => *unknown*
            [maxftp] => unlimited
            [maxlst] => unlimited
            [maxparked] => 2
            [maxpop] => unlimited
            [maxsql] => unlimited
            [maxsub] => unlimited
            [min_defer_fail_to_trigger_protection] => 5
            [owner] => ***
            [partition] => home
            [plan] => Standard
            [shell] => /usr/local/cpanel/bin/noshell
            [startdate] => 14 Feb 14 15:58
            [suspended] => 0
            [suspendreason] => not suspended
            [suspendtime] => SimpleXMLElement Object
                (
                )

            [theme] => x3
            [unix_startdate] => 1392393516
            [user] => ***
        )

    [status] => 1
    [statusmsg] => Ok
)
however, i cant access any of those in PHP.

i've tried all sorts, from accessing the properties directly:

PHP:
print($username->acct->user);
to looping over it:

PHP:
foreach($ar13bakk->acct as $key => $account){
        print_r($account->user);
    }
which gives:

Code:
SimpleXMLElement Object
(
    [0] => ar13bakk
)
and i still cant access that. I've tried looping over it, i've also tried accessing the object key ($account->user{'0'}) no joy ether.

So, what on earth am i missing?
 

N1ghteyes

Active Member
Mar 3, 2014
33
2
8
Reading, UK
cPanel Access Level
Root Administrator
Twitter
right.

After much messing about i descovered why this wasnt working. The data inside the object is also stored as an object. so for example, inside the origonal print_t() we had this:

Code:
SimpleXMLElement Object
(
    [acct] => SimpleXMLElement Object
        (
            [backup] => 0
            [disklimit] => 2000M
            [diskused] => 372M
            [domain] => ***
            [email] => ***
            [ip] => ***
            [is_locked] => 0
            [legacy_backup] => 1
            [max_defer_fail_percentage] => unlimited
            [max_email_per_hour] => unlimited
            [maxaddons] => *unknown*
            [maxftp] => unlimited
            [maxlst] => unlimited
            [maxparked] => 2
            [maxpop] => unlimited
            [maxsql] => unlimited
            [maxsub] => unlimited
            [min_defer_fail_to_trigger_protection] => 5
            [owner] => ***
            [partition] => home
            [plan] => Standard
            [shell] => /usr/local/cpanel/bin/noshell
            [startdate] => 14 Feb 14 15:58
            [suspended] => 0
            [suspendreason] => not suspended
            [suspendtime] => SimpleXMLElement Object
                (
                )

            [theme] => x3
            [unix_startdate] => 1392393516
            [user] => ***
        )

    [status] => 1
    [statusmsg] => Ok
)
so the structure would normally be something like $account(object)->acct(object)->disklimit(object)->2000M(string)

infact whats happening is that the values are also objects. The end result is that when attempting to access those values you instead key a key'd object, hence the:

Code:
SimpleXMLElement Object
(
    [0] => ar13bakk
)
to resolve the issue for now you can typecast with

PHP:
$disklimit = (string)$account->acct->disklimit;
hardly ideal but it works for now. If i get a chance, i'll see about posting a more perminent solution
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,913
2,201
363
Hello :)

Thank you for updating the thread with an initial solution to the problem you presented.

Thank you.