0

I am a newbie to programming and I am trying to find a solution for a response from a SOAP Server.

I am trying to get a user from a server and if the user ID is available it returns its user id but when no user is found it gives something like below.

[return] => stdClass Object
        (
            [user] => stdClass Object
                (
                  [associateduser] => stdClass Object
                                       (
                                        )

so in PHP, I am trying to define a condition like,

if(return->user->associateduser){
   echo something;
else{
   echo something;

This is not working and requesting someone help on how to work on this empty object using an if statement.

Thanks in advance.

  • use the response object, e.g. `$response` to reference the data that you need - `$response->return->user->associateduser` (see [doc](https://developer.cisco.com/docs/axl/#!php-quickstart/sample-excerpt-of-the-response-arrayobject)). – jibsteroos Jun 08 '20 at 20:43
  • Thanks for the comment. Sorry I didn't code here that but yes I added that and able to pull all other responses. this one returns a empty object and i dont know what to mention in the if statement like, if(the response tag = empty object) { i tried to put "", false, 0, NULL and nothing works. – axlprogrammer Jun 08 '20 at 20:52
  • [this](https://stackoverflow.com/questions/9411681/php-object-holding-xml-data) might help - use `isset()` – jibsteroos Jun 08 '20 at 20:55
  • thank you again. so i used like this, $toto = $response->return->user->associateduser; echo isset($toto); this gives a value of 1 which i understand 'true'. but i don't know what to put after that 'associateduser' as it has stdClass(). – axlprogrammer Jun 08 '20 at 21:07
  • you haven't shared the `$response` object structure, but I'm guessing when you do get a `user id` you access it with something like `$response->return->user->associateduser->id`? You might use `isset()` on the `id` property for your conditional statement? – jibsteroos Jun 08 '20 at 21:24
  • stdClass Object ( [return] => stdClass Object ( [user] => stdClass Object ( [associateduser]=> stdClass ( ) the above is the response for NO id return. stdClass Object ( [return] => stdClass Object ( [user] => stdClass Object ( [associateduser]=> stdClass ( [user] => axlprogrammer ) so If I use return->user->associateduser->user , i get the response as axlprogrammer. but for the invalid one i don't know what to use as it throws an error if I leave it like that. – axlprogrammer Jun 08 '20 at 21:29
  • I fixed this using a if like, if($vari ==new stdClass(''){ – axlprogrammer Jun 08 '20 at 22:14

0 Answers0