Convert SimpleXMLElement object to ArrayObject

liunx

Guest
Hi,

I have been experimenting with ArrayObject. I've successfully converted an object to an ArrayObject.

I did the following:


class Test
{
public $a = 'blaat';
public $b = 'aap';
public $c = 'noot';
public $d = 'mies';
}

$test = new Test();

$arrayobject = new ArrayObject($test);

echo $arrayobject->count();



This works fine. But now I want to convert a SimpleXMLElement object to an ArrayObject.
However, this does not work.

$sxe = simplexml_load_string('<xml><toet><aap>dasas</aap><mies>toet</mies><noot>dasda</noot></toet><blaat><aap>dasas</aap><mies>toet</mies><noot>dasda</noot></blaat></xml>','ArrayObject');

echo $sxe->count();


I get the following error:
ArrayObject::count() [<a href='http://www.phpbuilder.com/board/archive/index.php/function.count'>function.count</a>]: Array was modified outside object and is no longer an array

Am I doing something that is not possible?According to the manual, if you want to do that, then ArrayObject would need to extend SimpleXMLElement.
 
Back
Top