Solved

How do I access property of nested object in PHP?

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

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 108

Expert Comment

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

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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 dynamically set the form action using jQuery.

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now