Home » Tecnologia

Como solucionar o erro: Warning: unserialize() [function.unserialize]: Node no longer exists in

8 dezembro 2009 No Comment

Estava fazendo um blog em wordpress quando me deparei com o seguinte erro:

Warning: unserialize() [function.unserialize]: Node no longer exists in

Após uma googlada na internet, encontrei que o método serialize e unserialize não funcionam muito bem com o objeto SimpleXMLObject. Assim, é necessário extender essas duas funções para que funcione, deste modo:

	function serializemmp($toserialize){
		if(is_a($toserialize, "SimpleXMLElement")){
			$stdClass = new stdClass();
			$stdClass->type = get_class($toserialize);
			$stdClass->data = $toserialize->asXml();
		}
		return serialize($stdClass);
	}
 
	function unserializemmp($tounserialize){
		$tounserialize = unserialize($tounserialize);
		if(is_a($tounserialize, "stdClass")){
			if($tounserialize->type == "SimpleXMLElement"){
				$tounserialize = simplexml_load_string($tounserialize->data);
			}
		}
		return $tounserialize;
	}

A função serializemmp pega o objeto do tipo SimpleXMLElement e obtém o seu xml, serializando-o. A função unserializemmp pega o xml guardado, como string, e o transforma em um objeto do tipo SimpleXMLElement, permitindo que sejam usadas as funcionalidades do xml normalmente.

Para maiores detalhes da função, basta acessar o link do autor da função.

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.