无法从对象获取数组转换的数据

时间:2014-09-23 07:39:32

标签: php arrays codeigniter object

我有一个对象响应类型

    FirstGivingCreditCardDonationResponse Object ( [transactionId:FirstGivingCreditCardDonationResponse:private] => a-10d28597b9dc524bae6a02 
[rawResponse:FirstGivingCreditCardDonationResponse:private] => a-10d28597b9dc524bae6a020 
[responseCode:FirstGivingCreditCardDonationResponse:private] => 201 )

转换成数组后,它变为

Array ( [FirstGivingCreditCardDonationResponsetransactionId] => a-b15ed981602d994d87718e [FirstGivingCreditCardDonationResponserawResponse] => a-b15ed981602d994d87718e0 [FirstGivingCreditCardDonationResponseresponseCode] => 201 )

当我想要数组中的这些值时,它会显示

A PHP Error was encountered
Severity: Notice

Message: Undefined index: FirstGivingCreditCardDonationResponseresponseCode

Filename: controllers/campaign.php

Line Number: 132

1 个答案:

答案 0 :(得分:0)

据推测,您在此处使用此课程:https://github.com/firstgiving/FirstGiving-PHP-SDK/blob/master/src/FirstGivingCreditCardDonationResponse.php

我不会将对象转换为数组,只需通过公共方法访问其私有属性:

$ResponseObject::getTransactionID();
$ResponseObject::getRawResponse();
$ResponseObject::getResponseCode();

您可能需要包含该标头以定义类以便使用它