Node no longer exists error with Zend_Session

送分小仙女□ 提交于 2019-12-08 05:20:47

问题


Hi I am having issues with my my sessions using Zend Framework 1.7.6.

The problem exists when I try and store an array to the session, the session namespace also stores other userdata.

I am currently getting the following message in my stacktrace

Fatal error: Uncaught exception 'Zend_Session_Exception' with message 'Zend_Session::start() - 
...

Error #2 session_start() [function.session-start]: Node no longer exists Array 

The code where I think this is erroring is:

//now we add the user object to the session
    $usersession = new Zend_Session_Namespace('userdata');
    $usersession->user = $user;

    //we now get the users menu map        
    $menuMap = $this->processMenuMap($menuMapPath);

    $usersession->menus = $menuMap;

This error has only started to appear since trying to add an array to the session namespace.

Any ideas what could be causing the Node no longer exists Array message?

Many thanks


回答1:


Are you trying to store a SimpleXML object or something else libxml related in the session data?
That doesn't work because the underlying DOM tree isn't restored when the objects are unserialized during session_start(). Store the xml document (as string) instead.

You can achieve that e.g. by providing the "magic functions" __sleep() and __wakeup(). But __sleep() has to return an array with the names of all properties that are to be serialized. If you add another property you also have to change that array. That removes some of the automagic...

But if your menumap class has only a few properties it might be feasible for you.

<?php
class MenuMap {
    protected $simplexml = null;
    protected $xmlstring = null;

    public function __construct(SimpleXMLElement $x) {
        $this->simplexml = $x;
    }

    public function __sleep() {
        $this->xmlstring = $this->simplexml->asXML(); 
        return array('xmlstring');
    }   

    public function __wakeup() {
        $this->simplexml = new SimpleXMLElement($this->xmlstring);
        $this->xmlstring = null;
    }

    // ...
}



回答2:


You should store the XML string in the session. Alternatively, you could create a wrapper class around that XML string that either:

  • implements Serializable interface
  • implements the __sleep() and __wakeup() methods.

In those methods you could take care about the state of the object.



来源:https://stackoverflow.com/questions/1084256/node-no-longer-exists-error-with-zend-session

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