rfc:session-oo

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
rfc:session-oo [2011/06/03 00:44] – created arpadrfc:session-oo [2017/09/22 13:28] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== Object oriented session handlers  ====== ====== Object oriented session handlers  ======
-  * Version: 1.0 +  * Version: 1.1 
-  * Date: 2011-06-03+  * Date: 2011-06-20
   * Author: Arpad Ray <arpad@php.net>   * Author: Arpad Ray <arpad@php.net>
-  * Status: Under Discussion+  * Status: Implemented in PHP 5.4, [[https://wiki.php.net/rfc/session-oo/vote|Voting results]]
   * First Published at: http://wiki.php.net/rfc/session-oo   * First Published at: http://wiki.php.net/rfc/session-oo
   * Original discussion: http://marc.info/?l=php-internals&m=125886685408121&w=2   * Original discussion: http://marc.info/?l=php-internals&m=125886685408121&w=2
 +  * Current discussion: http://marc.info/?l=php-internals&m=130706393506471&w=2
  
 ===== Introduction ===== ===== Introduction =====
Line 13: Line 14:
 Currently users must override all six functions and have no way of calling the original ones. Currently users must override all six functions and have no way of calling the original ones.
  
-This patch exposes the original handler (files, memcached, etc.) in a new internal class called SessionHandler, and alters session_set_save_handler() to also accept a class name or object.+This patch exposes the original handler (files, memcached, etc.) in a new internal class called SessionHandler, and alters session_set_save_handler() to also accept an object of this class.
  
 Example uses of overriding/wrapping individual methods of a handler: Example uses of overriding/wrapping individual methods of a handler:
Line 22: Line 23:
 ===== Example ===== ===== Example =====
  
-<code>+<code php>
 <?php <?php
 class MySession extends SessionHandler { class MySession extends SessionHandler {
- public static function open($path, $name) { + public function read($key) { 
- echo 'Open ', session_id(), "\n"; + return str_rot13(parent::read($key));
- return parent::open($path, $name);+
  }  }
- public static function read($key) { + 
- echo 'Read ', session_id(), "\n"; + public function write($key, $data) { 
- return parent::read($key);+ return parent::write($key, str_rot13($data));
  }  }
 } }
  
-session_set_save_handler('MySession');+session_set_save_handler(new MySession);
  
 ?> ?>
Line 42: Line 42:
 ===== Usage notes ===== ===== Usage notes =====
  
-  * Calling session_set_save_handler(class) after session_set_save_handler(a, b, c, d, e, f) wouldn't transparently extend the first call since they share the same storage. However this can be achieved by calling the former functions manually from the class+  * Calling session_set_save_handler(object) after session_set_save_handler(a, b, c, d, e, f) wouldn't transparently extend the first call since they share the same storage. However this can be achieved by calling the former functions manually from the object
-  * Likewise multiple session_set_save_handler(class) calls simply replace each other; just extend the new class from the old one instead of SessionHandler to chain them.+  * Likewise multiple session_set_save_handler(object) calls simply replace each other; just extend the new class from the old one instead of SessionHandler to chain them.
   * An E_WARNING error is raised if the (parent) SessionHandler class is used (read/write/close/destroy) before open is called.   * An E_WARNING error is raised if the (parent) SessionHandler class is used (read/write/close/destroy) before open is called.
-  * Calling session_set_save_handler(object) merely gets the class from the object and proceeds as if session_set_save_handler(class) were called. 
  
-===== Patch =====+===== Patches =====
  
-The patch is available at http://spellign.com/patches/php-trunk-session-oo7.patch+http://spellign.com/patches/php-trunk-session-oo12.patch 
 + 
 +http://spellign.com/patches/php-5.4-session-oo12.patch 
 + 
 +http://spellign.com/patches/php-trunk-session-oo12-tests.patch
  
 ===== Changelog ===== ===== Changelog =====
  
-2011-06-03 Arpad Ray: Initial RFC creation+  * 2011-06-03 Arpad Ray: Initial RFC creation 
 +  * 2011-06-20 Arpad Ray: Updated to reflect new patches 
 +  * 2011-06-20 Arpad Ray: Updated patches 
 +  * 2011-06-27 Arpad Ray: Updated patches 
  
  
rfc/session-oo.1307061854.txt.gz · Last modified: 2017/09/22 13:28 (external edit)