Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do I access property of nested object in PHP?

Posted on 2016-11-14
3
Medium Priority
?
132 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 111

Accepted Solution

by:
Ray Paseur earned 2000 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 111

Expert Comment

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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

This article discusses how to create an extensible mechanism for linked drop downs.
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…
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

670 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