Solved

How do I access property of nested object in PHP?

Posted on 2016-11-14
3
52 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
  • 2
3 Comments
 
LVL 109

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 109

Expert Comment

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

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

776 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