Flourish PHP Unframework
This is an archived copy of the forum for reference purposes

fSession::setLength() must be called before...

posted by audvare 8 years ago

I am totally sure I have not called any fSession methods before calling setLength().

I get this error: Fatal error: Uncaught exception 'fProgrammerException' with message 'fSession::setLength() must be called before any of fSession::add(), fSession::clear(), fSession::enablePersistence(), fSession::get(), fSession::open(), fSession::set() or session_start()'

class SomeClass {
    public static function setupAuthorization() {
    fSession::setLength('30 minutes', '1 week');
    //fSession::setPath('/writable-dir');
    fSession::enablePersistence();
    
    fAuthorization::setLoginPage(Sutra::getConfig()->getBaseUrl().'login');
    fAuthorization::setAuthLevels(array('admin' => 100, 'user' => 50, 'guest' => 25));
  }
  
  public static function render() {
    self::getDb();
    self::getConfig();
    self::getPage();
    self::setupAuthorization();
  }
}

NONE of the other static functions functions call any fSession methods.

I can't tell from the code you've posted, but that error message is for the entire lifecycle of that request.

If you are following the standard architecture and have some sort of init.php that gets called for every request you will probably want to check there to make sure nothing is opening fSession.

Be aware that even if you don't see fSession::open() there are many classes and functions that call it. I would bet money on fMessaging being the issue, especially if you followed the header examples here. fMessaging::check(), fMessaging::create(), fMessaging::get(), and fMessaging::show() all call into fSession.

Follow your execution flow using a debugger like MacGDBp or one of the fine debuggers built into Eclipse or Netbeans, you can set a break point in every fSession function and then look at your stack trace to see who is calling it before SomeClass.

posted by ihumanable 8 years ago

What about fAuthorization? How much involvement does that have with fSession?

I swapped and put setupAuthorization at the top, since this static function render is just called from index.php. That has fixed the problem.

posted by audvare 8 years ago

fAuthorization calls into fSession quite a bit, look at fAuthorization

From just a quick search it looks like the following function call into fSession.

fAuthorization::checkLoggedIn() fAuthorization::destroyUserInfo() fAuthorization::getRequestedUrl() fAuthorization::getUserACLs() fAuthorization::getUserAuthLevels() fAuthorization::getUserToken() fAuthorization::setRequestedUrl() fAuthorization::setUserACLs() fAuthorization::setUserAuthLevels() fAuthorization::setUserToken()

It's probably a good idea to have an init script and in that script call fSession::setLength() Since this is normally an application wide setting having it be part of your bootstrap isn't a bad idea.

posted by ihumanable 8 years ago