Scripta55
Scripta55

Reputation: 49

accessing object from soap service

I am trying to access an object from a soap service. My objective is to get the value in the property of ID which is 53. Prior to this point i have used simplexml_load_string to get to the object you see below. however when trying to access the object using -> or [''] key notations it throws an error. i believe the @ in the key is causing a problem.

i get the following result:

as vardump:

object(SimpleXMLElement)[1951]
  public '@attributes' => 
    array (size=1)
      'id' => string '53' (length=2)

as dd result:

SimpleXMLElement {#1951 ▼
  +"@attributes": array:1 [▼
    "id" => "53"
  ]
}

Debug section:

 $result =$service->call('DisplayCategories', [$data]);

            $result = simplexml_load_string((string)$result->DisplayCategoriesResult->any);
           // dd($result);
            $result = $result->categories->category;
            //dd($result);
            $tempArr = array();

            foreach($result as $item)
            {
              //  var_dump(html_entity_decode($item));
                var_dump($item);
                dd(((object)$item));
              //  dd(preg_replace(array("@"),'',$item));
              //  dd(@simplexml_load_string($item));
                dd($item->attributes('id'));
                $simple = $item->attributes('id');
                $resulters = ($item->attributes('id'));
               dd($resulters);
            }

            $this->setResult($result);
        });

Upvotes: 0

Views: 60

Answers (1)

Ohgodwhy
Ohgodwhy

Reputation: 50797

@attributes is a function which returns an array, you don't access it directly. Simply Alias it to a variable, then work with the indices once you've done that.

$atts = $item->attributes();
dd($atts['id']);

Also, as a side note, cast your objects to a string prior to dumping them when it's a simple xml object, otherwise you'll see some funky stuff that you probably aren't looking for, anyway.

Upvotes: 2

Related Questions