Php nesneleri birleştirme nasıl?

0 Cevap php

I'm currently re-writing a class which handles xml files. Depending on the xml file and it's structure I sometimes need to merge objects.

Bunu aldıktan sonra Sağlar ki:

<page name="a title"/>


: Ve başka bir zaman ben bu var

<page name="a title">
  <permission>administrator</permission>
</page>

Before, I needed only the attributes from the "page" element. That's why a lot of my code expects an object containing only the attributes ($loadedXml->attributes()).
Now there are xml files in which the

<permission> 

element is required.
I did manage to merge the objects (though not as I wanted) but I can't get to access one of them (most probably it's something I'm missing).

To merge my objects I used this code:

(object) array_merge(
                     (array) $loadedXml->attributes(), 
                     (array) $loadedXml->children()
                    );


This is what I get from print_r():

stdClass Object ( 
    [@attributes] => Array ( [name] => a title ) 
    [permission]  => Array ( [0] => administrator ) 
) 


So now my question is how to access the @attributes method and how to move the arrays from [@attributes] to the main object?

0 Cevap