get the value of object inside the array in php - php

i am trying to get the merchantAccountId value from given below array
Array
(
[status] => 1
[result] => __PHP_Incomplete_Class Object
(
[__PHP_Incomplete_Class_Name] => Braintree_Result_Successful
[success] => 1
[_returnObjectName:Braintree_Result_Successful:private] => transaction
[transaction] => __PHP_Incomplete_Class Object
(
[__PHP_Incomplete_Class_Name] => Braintree_Transaction
[_attributes] => Array
(
[id] => 6vk28p
[status] => submitted_for_settlement
[type] => sale
[currencyIsoCode] => USD
[amount] => 800.00
[merchantAccountId] => contentorganisation
[orderId] =>
[createdAt] => DateTime Object
(
[date] => 2015-07-24 11:51:42
[timezone_type] => 3
[timezone] => UTC
)
)
)
)
)
my code is $result['result']['transaction'] .
when i print this i got this error
Fatal error: Cannot use object of type __PHP_Incomplete_Class as array in.

The result is OBJECT not array, so you have to call it by:
Array['result']->transaction->_attributes['id']

I work at Braintree. You should be able to access the merchant account ID by calling $result->transaction->merchantAccountId, (see Braintree docs).

Related

Cannot access protected property PHP

trying to get values from object array, here is error and what i tried so far.
echo "<pre>";print_r($response->_value());//Call to undefined method OmiseCharge::_value()
echo "<pre>";print_r($response->_value); //Cannot access protected property PHP
actual array :
OmiseCharge Object
(
[OMISE_CONNECTTIMEOUT:OmiseApiResource:private] => 30
[OMISE_TIMEOUT:OmiseApiResource:private] => 60
[_values:protected] => Array
(
[object] => list
[from] => 2012-08-01T00:00:00+00:00
[to] => 2016-10-20T00:00:00+00:00
[offset] => 0
[limit] => 20
[total] => 201
[order] => chronological
[location] => /charges
[data] => Array
(
[0] => Array
(
[object] => charge
[id] => chrg_test_##############
[livemode] =>
echo "<pre>";print_r($response->offsetGet('data'));
worked thanks.
to access protected member of a call you need to implement getter method in class which are type of public.

How to get value out of this...?

Can someone explain me how to get data out of this...like if I just want subject, description..etc...
stdClass Object
(
[tickets] => Array
(
[0] => stdClass Object
(
[url] => https://codemymobilecom.zendesk.com/api/v2/tickets/1.json
[id] => 1
[external_id] =>
[via] => stdClass Object
(
[channel] => sample_ticket
[source] => stdClass Object
(
[from] => stdClass Object
(
)
[to] => stdClass Object
(
)
[rel] =>
)
)
[created_at] => 2015-04-22T08:30:29Z
[updated_at] => 2015-05-19T06:01:22Z
[type] => incident
[subject] => This is a sample ticket requested and submitted by you
[raw_subject] => This is a sample ticket requested and submitted by you
[description] => This is the first comment. Feel free to delete this sample ticket.
[priority] => high
[status] => closed
[recipient] =>
[requester_id] => 794599791
[submitter_id] => 794599791
[assignee_id] => 794599791
[organization_id] => 39742491
[group_id] => 24344491
[collaborator_ids] => Array
(
)
[forum_topic_id] =>
[problem_id] =>
[has_incidents] =>
[due_at] =>
[tags] => Array
(
[0] => sample
[1] => zendesk
)
[custom_fields] => Array
(
)
[satisfaction_rating] =>
[sharing_agreement_ids] => Array
(
)
[fields] => Array
(
)
[followup_ids] => Array
(
)
[brand_id] => 565681
)
[1] => stdClass Object
(
[url] => https://codemymobilecom.zendesk.com/api/v2/tickets/10.json
[id] => 10 //multiple object like [0]...
Thanks...Any help would be great..
When you need to access to array's key, use []. When you have object, use ->.
echo $obj->tickets[0]->subject; // returns first subject
echo $obj->tickets[0]->description; // returns first description
You can put it into foreach loop, of course to gain all subjects, etc.
It's STD object so use properties
$obj->tickets[0]->subject
$obj->tickets[0]->description
You can obviously loop tickets
foreach($obj->tickets as $ticket)
{
echo $ticket->subject;
echo $ticket->description
}
this is an std object.to get subject and description follow this
$obj->tickets[0]->subject;
$obj->tickets[0]->description;
if you feel better in array just make it array using this code
$array = get_object_vars($obj);

HubSpot api json decode

I am trying to parse some data out of the Hubspot API response. The response looks like this json_decoded:
stdClass Object(
[addedAt] => 1411052909604
[vid] => 24
[canonical-vid] => 24
[merged-vids] => Array
(
)
[portal-id] => XXXXX
[is-contact] => 1
[profile-token] => AO_T-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
[profile-url] => https://app.hubspot.com/contacts/XXXXX/lists/public/contact/_AO_T-XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
[properties] => stdClass Object
(
[lastname] => stdClass Object
(
[value] => testtt
)
[firstname] => stdClass Object
(
[value] => test
)
[lastmodifieddate] => stdClass Object
(
[value] => 1411052906670
)
)
[form-submissions] => Array
(
[0] => stdClass Object
(
[conversion-id] => 85d24dd2-9ee9-4d47-b8f3-3035acbd8f3b
[timestamp] => 1411052834097
[form-id] => fb16efd9-23cc-4511-889c-204fc8b41dba
[portal-id] => 401824
[page-url] => http://wbl-1.hs-sites.com/test
[canonical-url] => http://wbl-1.hs-sites.com/test
[content-type] => landing-page
[page-title] => test
[page-id] => 1570433242
[title] => Default Form (Sample)
[first-visit-url] => http://wbl-1.hs-sites.com/test
[first-visit-timestamp] => 1411052722970
[meta-data] => Array
(
)
)
)
[list-memberships] => Array
(
)
[identity-profiles] => Array
(
[0] => stdClass Object
(
[vid] => 24
[identities] => Array
(
[0] => stdClass Object
(
[type] => EMAIL
[value] => test#user.com
[timestamp] => 1411052834097
)
[1] => stdClass Object
(
[type] => LEAD_GUID
[value] => 0b6acf21-6cee-4c7b-b664-e65c11ee2d8e
[timestamp] => 1411052834201
)
)
)
)
[merge-audits] => Array
(
)
)
I'm looking specifically to try to dig out an email inside the indentities-profile area.
I've tried to do the following:
echo $results->contacts[0]->identity-profiles;
But it just gives me a value of 0
Then I try to go further into the array by doing:
echo $results->contacts[0]->identity-profiles[0];
But at that point - I get a parse error:
Parse error: syntax error, unexpected '['
What am I doing wrong? And how can I dig all the way down to
identity-profiles[0]->identities->[0]->value
which should equal: test#user.com
What am I missing?
As mentioned in the comment I would suggest to decode the JSON to an associative array by passing true as second parameter to json_decode. Example: json_decode($data, true) Than you could access your identity profiles by:
$results['contacts'][0]['identitiy-profiles']
If you still want to get the results as an object you have to access the properties the following way because they contain a -:
$results->contacts[0]->{'identity-profiles'}

how to convert Object array to array while single value returning

how to convert Object array to array while single value returning ,
here is the o/p what i am getting while i am getting only one hotel, how can i convert it in a way to access it as a 0th [0] value shown in code. i have problems in accessing when i m getting single hotel in o/p. print_r($result); via foreach()
stdClass Object
(
[cityId] => 000000000020
[checkInDate] => 2013-12-20
[checkOutDate] => 2013-12-21
[customerId] =>
[customerAccountType] => SH01
[customerType] =>
[currency] => INR
[noOfRoomsRequested] => 1
[searchAvailabilityResult] => stdClass Object
(
[hotelId] => IXW1
[hotelName] => Ginger Jamshedpur
)
)
===what i want is ================================
stdClass Object
(
[cityId] => 000000000020
[checkInDate] => 2013-12-20
[checkOutDate] => 2013-12-21
[customerId] =>
[customerAccountType] => SH01
[customerType] =>
[currency] => INR
[noOfRoomsRequested] => 1
[searchAvailabilityResult] => Array
(
[0] => stdClass Object
(
[hotelId] => IXW1
[hotelName] => Ginger Jamshedpur
)
)
)
in case of single value
$result->searchAvailabilityResult = array($result->searchAvailabilityResult);
Many thanks to #Maciej Sz
$result->searchAvailabilityResult = get_object_vars($result->searchAvailabilityResult);

How to find out Yahoo email address using Yahoo API PHP

so heres my predicament.
Currently using Yahoo API with PHP in order to use a 'Login with Yahoo' Function on my site.
I have managed to retrieve my entire profile. Trouble is, I can't directly display the primary email associated with the account.
If I use print_r($profile) I get everything dumped from my profile. It looks like this (personal data removed):
stdClass Object ( [uri] => http://social.yahooapis.com/v1/user/*********/profile [guid] => ***** [birthdate] => / [created] => 2010-04-22T20:47:48Z [emails] => Array ( [0] => stdClass Object ( [handle] => **#gmail.com [id] => 1 [type] => HOME ) [1] => stdClass Object ( [handle] => ****#yahoo.com [id] => 2 [primary] => 1 [type] => HOME ) ) [familyName] => Surname [gender] => M [givenName] => Ricki [image] => stdClass Object ( [height] => 192 [imageUrl] => http://l.yimg.com/dh/ap/social/profile/profile_b192.png [size] => 192x192 [width] => 192 ) [lang] => en-US [memberSince] => 2010-04-08T11:22:56Z [nickname] => Ricki [profileUrl] => http://profile.yahoo.com/*********** [updated] => 2013-03-03T18:12:22Z [isConnected] => )
Using $profile->emails->handle yields nothing however. Any ideas on what to do? I can use $profile->emails which returns an Array, displayed simply as 'Array' but if i try to select from the array i get an error:
"Catchable fatal error: Object of class stdClass could not be converted to string"
Anyone?
$profile->emails[0]->handle will give you the first handle in the system.
You can also do foreach($profile->emails as $email) { print $email->handle; }

Categories