SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Dec 2008
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post session_set_save_handler & MySQL

    I'm *trying* to build a session handler class that writes to a MySQL DB. I purchased the book "PHP Anthology" and have Googled an endless supply of different takes on the issue. I have yet to have 100% success.

    I have a couple of questions:
    1) I have never seen this before - can anyone explain to me WHY this works:
    Code:
    session_set_save_handler( array($this, 'SessionOpen'), 
    			array($this, 'SessionClose'), 
    			array($this, 'SessionRead'), 
    			array($this, 'SessionWrite'), 
    			array($this, 'SessionDestroy'), 
    			array($this, 'SessionClean') ) ;
    I mean I tried (inside a class):
    Code:
    session_set_save_handler($this->SessionOpen, $this->SessionClose, etc..
    and it didnt seem to work - so Im just trying to understand why session_set_save_handler() takes this list in this way (arrray($this, 'name')

    the other question I have is do any of you have a session_set_save_handler() class that works with a database?

    Thanks in advance for any insight!

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    php isn't like javascript for example, where you can pass a reference to a function by ommiting the (). So the only way is to tell php what method you want called, and then tell it which object or class you want the method called upon.

    session_set_save_handler() accepts callbacks, like many other php functions. More info on callbacks:
    http://www.php.net/callback

  3. #3
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $this is a keyword which can be used with the arrow operator in instance methods to refer to the object on which the currently executing method has been invoked.

    as for the working example of the session_set_save_handler take a look here
    my mobile portal
    ghiris.ro


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •