PHP Node no longer exists问题处理

在PHP里面用到了“simplexml_load_file” 想把它返回的某个节点值直接写到SESSION里面,但却出现了警告提示

“Warning: session_start() [function.session-start]: Node no longer exists in。。。

原文解释: This is an example of PHP (version 5.1.2) throwing a warning when you are trying to insert a value into the $_SESSION store. The most common cause for this is when: 1. You have a SimpleXML document 2. You want to save one of the node values into the $_SESSION store 3. You make a direct assignment like: $_SESSION[‘myKey’] = $myXmlDoc->FirstNode At this point, PHP will throw the warning about ‘Node no longer exists’. The remedy is that you need to explicitly cast the XML node value before you assign it. For example, $_SESSION[‘myKey’] = (string)$myXmlDoc->NodeValue This should fix the problem. This is also described in a PHP bug report:


当你把一个XML文档,或者某一个节点的值放到SESSION里时都会发生 Node no longer exists 错误,解决方法是先把节点的值转化为字符型,再写到SESSION里就可以了。 如:$_SESSION[‘name’] = (string)$xml->name;


电子邮件地址不会被公开。 必填项已用*标注

This site uses Akismet to reduce spam. Learn how your comment data is processed.