-6

i am not able to get array from object:

please see my code below:

 print_r($product_ser_id);

Print result:

WHMCS\Service\Service Object
(
    [table:protected] => tblhosting
    [columnMap:protected] => Array
        (
            [clientId] => userid
            [productId] => packageid
            [serverId] => server
            [registrationDate] => regdate
            [paymentGateway] => paymentmethod
            [status] => domainstatus
            [promotionId] => promoid
            [overrideAutoSuspend] => overideautosuspend
            [overrideSuspendUntilDate] => overidesuspenduntil
            [bandwidthUsage] => bwusage
            [bandwidthLimit] => bwlimit
            [lastUpdateDate] => lastupdate
            [firstPaymentAmount] => firstpaymentamount
            [recurringAmount] => amount
            [recurringFee] => amount
        )
}

here i have to get value from [productId]

i have already tested as: $product_ser_id -> attributes:protected;

its show error as:

ParseError: syntax error, unexpected ':' in 

and i know there many example so please don't tell duplicate untill you really understand my issues.

Please help

thanks

9
  • Don't you have any getters ? Commented Jan 10, 2019 at 8:36
  • Possible duplicate of How to get data from array in object Commented Jan 10, 2019 at 8:37
  • 1
    Without extending WHMCS\Service\Service or changing WHMCS\Service\Service class you won't be able to get that array because its protected. You could create an adapter and extend the Service, and then create a method that returns it. Commented Jan 10, 2019 at 8:37
  • stackoverflow.com/questions/54124676/… Commented Jan 10, 2019 at 8:42
  • @CésarFerreira please help, mostly peoples are saying duplicate without understand protected Commented Jan 10, 2019 at 8:49

1 Answer 1

0

issues solved with the answer of @drewish

Source: ReflectionClass

Code:

 function accessProtected($obj, $prop) {
  $reflection = new ReflectionClass($obj);
  $property = $reflection->getProperty($prop);
  $property->setAccessible(true);
  return $property->getValue($obj);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.