'Serialization of 'SimpleXMLElement' is not allowed Error insert in session xml value [duplicate]

旧城冷巷雨未停 提交于 2019-12-23 10:07:42

问题


Hi all I have a site developed in codeigniter. I'm parsing an xml that I retrieve from a server and I want to put the return value into a session variable. But return me this error:

Fatal error: Uncaught exception 'Exception' with message 'Serialization of 'SimpleXMLElement' is not allowed

My PHP version on my vps is: 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);      
 } 

回答1:


may be try changing it to string before adding, like:

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);      
 } 


来源:https://stackoverflow.com/questions/15473797/serialization-of-simplexmlelement-is-not-allowed-error-insert-in-session-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!