Access to object members in PHP

I call the WCF service in PHP, which returns this thing to me: (The service I call returns a C # structure)

object(stdClass)#70 (1) {
  ["SiteInterop_CreateContactAndOpportunityResult"]=>
    object(stdClass)#149 (5) {
      ["result"]=>
        bool(true)
      ["strAccountExec"]=>
        NULL
      ["strAccountId"]=>
        string(36) "bd346671-88ca-4966-971a-9dd499c7a689"
      ["strContactId"]=>
        string(36) "06a8808d-ed66-42f9-a821-00358213bb94"
      ["strOpportunityId"]=>
        string(36) "d4845fd0-18fb-4a40-8424-904866cb471e"
    }
}

The question is, how do I access the values? These values ​​are true Boolean and three attributes.

+3
source share
3 answers

To obtain result

$var->SiteInterop_CreateContactAndOpportunityResult->result;

To get guids

$var->SiteInterop_CreateContactAndOpportunityResult->strAccountId
$var->SiteInterop_CreateContactAndOpportunityResult->strContactId
$var->SiteInterop_CreateContactAndOpportunityResult->strOpportunityId
+3
source

make a link for more convenient use in the future,

$oResult = &$oStruct->SiteInterop_CreateContactAndOpportunityResult;

then go to

echo $oResult->strAccountId;

to get strAccountId value

+1
source

You could do (assuming that $returnedObjectis a returned object)

$strOpportunityId = $returnedObject
                                ->SiteInterop_CreateContactAndOpportunityResult
                                ->strOpportunityId
0
source

All Articles