« Return to Thread: Zend_Session coupled with Zend_Auth throws an exception in ZF >1.0.3

Zend_Session coupled with Zend_Auth throws an exception in ZF >1.0.3

by Psyke :: Rate this Message:

Reply to Author | View in Thread

hello,

I have the following code in my bootstrap (it's a htaccess prepend file)

      //Zend_Loader
      require_once ('Zend/Loader.php');

      //Init
      Zend_Loader::registerAutoload ();

      Zend_Session::start ();

      $authInstance = Zend_Auth::getInstance();
     
      $d = $authInstance->hasIdentity(); // <- this line sucks
     

I'm using ZF 1.5.2 snapshot 20080519-9472

With this code I get an exception

Fatal error: Uncaught exception 'Zend_Session_Exception' with message 'The session was explicitly destroyed during this request, attempting to re-start is not allowed.' in /home/webdev/webstage/devintra/frameworkSnapshot/library/Zend/Session.php:364 Stack trace: #0 /home/webdev/webstage/devintra/frameworkSnapshot/library/Zend/Session/Namespace.php(116): Zend_Session::start(true) #1 /home/webdev/webstage/devintra/frameworkSnapshot/library/Zend/Auth/Storage/Session.php(87): Zend_Session_Namespace->__construct('Zend_Auth') #2 /home/webdev/webstage/devintra/frameworkSnapshot/library/Zend/Auth.php(91): Zend_Auth_Storage_Session->__construct() #3 /home/webdev/webstage/devintra/frameworkSnapshot/library/Zend/Auth.php(133): Zend_Auth->getStorage() #4 /home/webdev/webstage/devintra/ssl/zfweb/prepend.php(81): Zend_Auth->hasIdentity() #5 {main} thrown in /home/webdev/webstage/devintra/frameworkSnapshot/library/Zend/Session.php on line 364

SO i've searched and found this difference in Zend/Session.php, (function start) between 1.5.2 and 1.0.3:

1.0.3:

if (self::$_sessionStarted) {
            return; // already started
}

1.5.2:

if (self::$_sessionStarted && self::$_destroyed) {
            require_once 'Zend/Session/Exception.php';
            throw new Zend_Session_Exception('The session was explicitly destroyed during this request, attempting to re-start is not allowed.');
}
if (self::$_sessionStarted) {
            return; // already started
}

When I comment the 4 fisrt lines it works like a charm.

I used this little code to switch between the framework snapshot and the old 1.0.3 version of the framework:

if ($_SERVER['REMOTE_ADDR']== '<my ip address>') {
        //test the development framework snapshot
        define ('ZEND_FRAMEWORK_DIR','/<my path>/frameworkSnapshot/library');
}else {
        // dev PATH TO ZEND FRAMEWORK (version 1.5.2 last snapshot)
        define ('ZEND_FRAMEWORK_DIR','/<my path>/framework/library');
}

The problem is Zend_Auth calls getStorage() and creates a new instance of Zend_Auth_Storage_Session through $this->setStorage(new Zend_Auth_Storage_Session()); Then, a new Zend_Session_Namespace is created which starts the session again. Zend_Session::start(true);

What I don't understand:
the destroy function in Zend_Session is never called. I've put a die('blah'); at first line and it never shows up :-/

can someone help me please?

Psy

 « Return to Thread: Zend_Session coupled with Zend_Auth throws an exception in ZF >1.0.3