views:

535

answers:

2

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

+3  A: 

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 __wake(). 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;
    }

    // ...
}
VolkerK
I do use simplexml. My menu/site map is stored in a xml file and I the try and store them in a Menu object that is stored into an array. Is there a way I can achieve what I am trying to do?
Grant Collins
+1  A: 

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

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

Ionuț G. Stan
Implementing Serializable here is certainly better than my __sleep/__wake example.
VolkerK