Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you use a @ symbol in the name of a PHP object

I've got an XML file that has the label @attributes for one of the names

SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [PART_NUMBER] => ABC123

I want to make a reference to this object like $product->@attributes['part_number'] but of course the @ symbol causes an error.

So how do I reference this item in the object?

like image 414
Dallas Clark Avatar asked Oct 15 '10 12:10

Dallas Clark


1 Answers

Well, in the case of SimpleXML, you'd call the $product->attributes() method as defined in the manual. That will give you an array mapping attribute names to values.

like image 111
VoteyDisciple Avatar answered Nov 03 '22 00:11

VoteyDisciple