SimpleXML objects in PHP cannot be serialized ____php

Source: Internet
Author: User

It is very convenient for a friend who is sure to deal with XML frequently to use simplexml_load_string, and he turns XML into an object. But if you want to serialize the object and cache it, be careful. There is no problem writing cache, but error reading cache, the error is "Node no longer exists in xxxx.php on line 15". The error occurs because of the deserialization of the SimpleXML object. It's probably a bug in PHP.

The following code can verify my experience and be careful when serializing SimpleXML objects later. ? Php
$data = <<< XML
? XML version = ' 1.0 '?>
< articles >
< article >
< title > Wang Kaiyuan PK Bill title >
Article >
Articles >
XML;
$xml = simplexml_load_string ($data);
$str = serialize ($xml);
echo "$str";
$new _xml = unserialize ($STR);
Echo Serialize ($new _xml). " " ;
?>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.