Solved

How do I access property of nested object in PHP?

Posted on 2016-11-14
3
62 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
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…

820 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