Node no longer exists using SimpleXML

前端 未结 2 1822
长发绾君心
长发绾君心 2021-01-23 00:00

Trying to cache an xml file using the build in wordpress function called get_transient but I\'m getting a php error:

unserialize() [function.unserialize]: Node

相关标签:
2条回答
  • 2021-01-23 00:31

    You shouldn't (can't?) serialize and unserialize the SimpleXML object. It's XML, which is a serialization format to begin with. This ain't Inception here!

    Call the asXML method to get the actual XML, then store that instead.

    0 讨论(0)
  • 2021-01-23 00:45

    Your $response_xml is an instance of the SimpleXMLElement class. A SimpleXMLElement should not be (un)serialized, because it wraps a resource within the object.

    Instead, serialize something which will happily survive the process; the raw response from the feed, all/part of the XML after loading it into the SimpleXMLElement and using the asXML() method, an array of the (likely string) values you want, or some other structure which is okay to be serialized.

    One thing to consider is that you will see the unserialize(): Node no longer exists warning in "older" (to use the term loosely) versions of PHP. As of PHP 5.3.2, the behaviour changed to throw an Exception with the message Serialization of 'SimpleXMLElement' is not allowed.

    0 讨论(0)
提交回复
热议问题