Serialization of "SimpleXMLElement" is not allowed. Insert error into session xml value

Hi everyone, I have a website developed by codeigniter. I am parsing the xml that I am retrieving from the server and want to put the return value in a session variable. But give me back this error:

Fatal error: throw exception "Exception" with the message "Serialization" SimpleXMLElement "is not allowed

My PHP version on my vps: PHP version 5.3.10-1ubuntu3.4

This is my code:

$xml = new SimpleXMLElement(curl_exec($ch2)); $error2=curl_getinfo( $ch2, CURLINFO_HTTP_CODE ); curl_close($ch2); foreach ($xml->DATA as $entry){ $code_travco = $entry->attributes()->COUNTRY_CODE; $name_en = $entry->COUNTRY_NAME; $newdata = array( 'code' => $code_travco, 'name_en' => $name_en ); $this->session->set_userdata($code_travco.'_nation_en', $newdata); } 
+4
source share
1 answer

you can try changing it to a string before adding, for example:

 foreach ($xml->DATA as $entry){ $code_travco = (string) $entry->attributes()->COUNTRY_CODE; $name_en = (string) $entry->COUNTRY_NAME; $newdata = array( 'code' => $code_travco, 'name_en' => $name_en ); $this->session->set_userdata($code_travco.'_nation_en', $newdata); } 
+14
source

All Articles