Solved

How do I access property of nested object in PHP?

Posted on 2016-11-14
3
108 Views
Last Modified: 2016-11-15
Hi,

I am having issues accessing the property of a nested object in PHP, in this particular case I am trying to access the Session

Result of print_r of object

echo "<pre>";
print_r($triodeServiceLogin);
echo "</pre>";

Open in new window


TriodeServiceLogin Object
(
    [result:TriodeWsdlClass:private] => TriodeStructLoginResponse Object
        (
            [LoginResult] => TriodeStructLoginResult Object
                (
                    [Code] => OK
                    [Message] => 
                    [Session] => eaphhl4dfrqraxdsywi3vinf
                    [result:TriodeWsdlClass:private] => 
                    [lastError:TriodeWsdlClass:private] => 
                    [internArrayToIterate:TriodeWsdlClass:private] => 
                    [internArrayToIterateIsArray:TriodeWsdlClass:private] => 
                    [internArrayToIterateOffset:TriodeWsdlClass:private] => 
                )

            [result:TriodeWsdlClass:private] => 
            [lastError:TriodeWsdlClass:private] => 
            [internArrayToIterate:TriodeWsdlClass:private] => 
            [internArrayToIterateIsArray:TriodeWsdlClass:private] => 
            [internArrayToIterateOffset:TriodeWsdlClass:private] => 
        )

    [lastError:TriodeWsdlClass:private] => Array
        (
        )

    [internArrayToIterate:TriodeWsdlClass:private] => 
    [internArrayToIterateIsArray:TriodeWsdlClass:private] => 
    [internArrayToIterateOffset:TriodeWsdlClass:private] => 
)

Open in new window


And

echo "<pre>";
print_r($triodeServiceLogin->getResult());
echo "</pre>";

Open in new window


Gives me

TriodeStructLoginResponse Object
(
    [LoginResult] => TriodeStructLoginResult Object
        (
            [Code] => OK
            [Message] => 
            [Session] => loz3tcgsufujukujyhi3ww03
            [result:TriodeWsdlClass:private] => 
            [lastError:TriodeWsdlClass:private] => 
            [internArrayToIterate:TriodeWsdlClass:private] => 
            [internArrayToIterateIsArray:TriodeWsdlClass:private] => 
            [internArrayToIterateOffset:TriodeWsdlClass:private] => 
        )

    [result:TriodeWsdlClass:private] => 
    [lastError:TriodeWsdlClass:private] => 
    [internArrayToIterate:TriodeWsdlClass:private] => 
    [internArrayToIterateIsArray:TriodeWsdlClass:private] => 
    [internArrayToIterateOffset:TriodeWsdlClass:private] => 
)

Open in new window

0
Comment
Question by:jwleys
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 41886989
Untested code, but probably close to right, at least in principle...
$res = $triodeServiceLogin->getResult();
echo (string)$res->TriodeStructLoginResponse->LoginResult->Session;

Open in new window

Going forward, you can use var_export() to examine these data elements.  PHP var_export() produces executable code from the data structures, making it easier for us to test any solutions we propose.
0
 

Author Closing Comment

by:jwleys
ID: 41887021
Thanks, you pointed me in the right direction, a var_export really helped me a:

$res = $triodeServiceLogin->getResult();
echo (string)$res->LoginResult->Session;

resolved my issue :)
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 41887733
Excellent!  Thanks for the points and thanks for using E-E, ~Ray
0

Featured Post

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question