Convertir un objeto SimpleXML en una matriz [cerrado]

Me encontré con esta función de convertir un objeto SimpleXML en una matrizaqu:

/**
 * function object2array - A simpler way to transform the result into an array 
 *   (requires json module).
 *
 * This function is part of the PHP manual.
 *
 * The PHP manual text and comments are covered by the Creative Commons 
 * Attribution 3.0 License, copyright (c) the PHP Documentation Group
 *
 * @author  Diego Araos, diego at klapmedia dot com
 * @date    2011-02-05 04:57 UTC
 * @link    http://www.php.net/manual/en/function.simplexml-load-string.php#102277
 * @license http://www.php.net/license/index.php#doc-lic
 * @license http://creativecommons.org/licenses/by/3.0/
 * @license CC-BY-3.0 <http://spdx.org/licenses/CC-BY-3.0>
 */
function object2array($object)
{
    return json_decode(json_encode($object), TRUE); 
}

Así que mi adopción de cadenas XML es como:

function xmlstring2array($string)
{
    $xml   = simplexml_load_string($string, 'SimpleXMLElement', LIBXML_NOCDATA);

    $array = json_decode(json_encode($xml), TRUE);

    return $array;
}

Funciona bastante bien, pero parece un poco hacky? ¿Existe una forma más eficiente / robusta de hacer esto?

Sé que el objeto SimpleXML está lo suficientemente cerca de una matriz porque hace uso de la interfaz ArrayAccess en PHP, pero aún así no funciona muy bien como matriz con matrices multidimensionales, es decir, bucle.

Gracias a todos por cualquier ayuda

Respuestas a la pregunta(2)

Su respuesta a la pregunta