I am working with an API that returns XML. I use simplexml_load_string to convert it to an object.
I then connect to a mysql DB and do:I store that value as a BLOB.PHP Code://$parsed is the object.
$obj_for_DB=mysql_real_escape_string(serialize($parsed));
I pulled it out and process it like this:
The problem I am having now is that $new_object is an instance of stdClass and I want to know if it is identical to $parsed (besides being a different class). Neither "==" or "===" is going to do it. I tried running both objects through get_object_vars and comparing the arrays, but that didn't seem to work either. When I print_r the two objects, they look the same except for the class name, but there's so much data that I'd like to find a way to programatically compare them at least once during my testing phase. Any ideas? Is there a way to unserialize my simpleXML object without converting it, or is there a way to compare all the properties and their values regarless of the difference in class?PHP Code:$SQL="SELECT * FROM test_table";
$result=mysql_query($SQL);
$row=mysql_fetch_assoc($result);
$new_object=sxml_unserialze($row['object']);
//I had to use this custom function because of an error unserializing simpleXML elements.
//error like "SimpleXMLElement - Warning: unserialize() [function.unserialize]: Node no longer exists in … .php"
//found on PHP.net. Work around for error on unserializing SimpleXML object.
function sxml_unserialze($str)
{
return unserialize(str_replace(array('O:16:"SimpleXMLElement":0:{}', 'O:16:"SimpleXMLElement":'), array('s:0:"";', 'O:8:"stdClass":'), $str));
}



Reply With Quote
Bookmarks