note 29035 deleted from function.session-set-save-handler by danbrown
| From: | danbrown@php.net | Date: | Sun, 23 Jan 2011 16:21:49 +0000 |
| Subject: | note 29035 deleted from function.session-set-save-handler by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-176057@lists.php.net to get a copy of this message | ||
Note Submitter: Joe Wheeler
----
If you happen to want to build a session manager object you can set the handlers from inside the
class. This helps to keep the class encapsulated which helps make it nice and reusable.
class Session_manager {
...
session_set_save_handler(
array(& $this, 'session_open_method'),
array(& $this, 'session_close_method'),
array(& $this, 'session_read_method'),
array(& $this, 'session_write_method'),
array(& $this, 'session_destroy_method'),
array(& $this, 'session_gc_method')
);
...
}
Each handler is identified by an array containing a self-reference to the instance (note the &)
and a string identifying a method in the session manager class.
Remember that the new operator passes back a copy of the object. This is important if you want to
call session_set_save_handler() from inside the class constructor. You must remember to use another
reference when you create the instance...
$my_session_manager = & new Session_manager;
Otherwise the session handlers will be assigned to an instance which is created by the new operator
and NOT to the copy which is stored in the variable $my_session_manager.