Save session to DB "Using $this when not in object context"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    Save session to DB "Using $this when not in object context"

    Hey guys,

    My brains asleep and I don't know what's wrong with my session class.

    I'm over riding session with sesstion_set_sa ve_handler() in a class;

    When in my member functions (open, close, read) I use "$this" I get the error "Using $this when not in object context".

    Here's my constructor:

    [PHP]

    /**
    * @desc Constructor
    */
    function __construct
    (
    )
    {

    session_set_sav e_handler(array (&$this, 'open'),
    array(&$this, 'close'),
    array(&$this, 'read'),
    array(&$this, 'write'),
    array(&$this, 'destroy'),
    array(&$this, 'gc'));
    try
    {
    $this->sessionVO = new SessionVO();
    $this->sessionDAO = new DAO($this->sessionVO);

    $this->maxLifeTime = get_cfg_var("se ssion.gc_maxlif etime"); // or set it to something else.
    }
    catch (Exception $e)
    {
    die($e->getMessage() );
    }

    }

    [/PHP]

    here's my open method


    [PHP]

    /**
    * @desc Opens the session
    * @return bool
    */
    public static function open
    (
    )
    {
    $dbLink = $this->sessionDAO->getDBLink();
    return !is_null($dbLin k);
    }

    [/PHP]

    My data members are private ($sessionVO and $sessionDAO)


    pbmods...ronver donk...anybody? Any suggestion is appreciated.

    Yours,

    Dan
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    Nevermind guys.

    it fixed itself.

    after commenting out all lines and emptying the functions one by one (it would just throw the error on the next function that was using it)

    Then uncommented open() method which uses $this , but the error wouldn't point there anymore.

    I uncommented them each and fixed other errors not related to this as they came up.

    I really can't explain it, but meh...whatever.

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      Heya, Dan.

      You made open(), etc. static methods, which can't use $this.

      [EDIT: Incidentally, PHP automatically hands off e.g., session max age to certain methods. For an example, see this article.]

      Comment

      • dlite922
        Recognized Expert Top Contributor
        • Dec 2007
        • 1586

        #4
        Originally posted by pbmods
        Heya, Dan.

        You made open(), etc. static methods, which can't use $this.

        [EDIT: Incidentally, PHP automatically hands off e.g., session max age to certain methods. For an example, see this article.]
        Yes sorry haven't been keeping this updated. Turns out I did that and still couldn't. Yes weird, but I'm just now declaring the new objects instead of using data members.

        Just for kicks, i'll go back and just make them public functions, but I'm 100% i did this and didn't work.

        Aww, Did i inspire you to write that article. I feel loved, man.

        I'll read it for sure.

        see ya,


        Dan

        Comment

        Working...