Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"At sign" @ in SimpleXML object?

Tags:

php

simplexml

This is the output of print_r() run on a typical SimpleXMLElement object:

SimpleXMLElement Object
(
    [@attributes] => Array
        (

        )
)

What does the @ sign mean?

like image 910
Andy Hin Avatar asked Dec 01 '10 18:12

Andy Hin


2 Answers

This is a SimpleXMLElement object. The '@attributes' row is an internal representation of the attributes from the XML element. Use SimpleXML's functions to get data from this object rather than interacting with it directly.

like image 93
Rocket Hazmat Avatar answered Oct 04 '22 07:10

Rocket Hazmat


All those answers about error control are incorrect. The @ doesn't mean anything. That's how the property is called internally, but do not rely on this. Do not rely on print_r() or var_dump() when dealing with SimpleXML. SimpleXML does a lot of "magical" things that are not correctly represented by print_r() and var_dump().

If you need to know what's "inside" a XML fragment, just use ->asXML() on it.

like image 22
Josh Davis Avatar answered Oct 04 '22 06:10

Josh Davis