File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / session / tests / session_set_save_handler_class_003.phpt
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue May 29 12:34:42 2012 UTC (12 years, 1 month ago) by misho
Branches: php, MAIN
CVS tags: v5_4_3elwix, v5_4_29p0, v5_4_29, v5_4_20p0, v5_4_20, v5_4_17p0, v5_4_17, HEAD
php 5.4.3+patches

    1: --TEST--
    2: Test session_set_save_handler() : inheritance
    3: --INI--
    4: session.save_handler=files
    5: session.name=PHPSESSID
    6: --SKIPIF--
    7: <?php include('skipif.inc'); ?>
    8: --FILE--
    9: <?php
   10: 
   11: ob_start();
   12: 
   13: /* 
   14:  * Prototype : bool session_set_save_handler(SessionHandler $handler [, bool $register_shutdown_function = true])
   15:  * Description : Sets user-level session storage functions
   16:  * Source code : ext/session/session.c 
   17:  */
   18: 
   19: echo "*** Testing session_set_save_handler() : inheritance ***\n";
   20: 
   21: class MySession3 extends SessionHandler {
   22: 	public $i = 0;
   23: 	public function open($path, $name) {
   24: 		++$this->i;
   25: 		return parent::open($path, $name);
   26: 	}
   27: 	public function read($key) {
   28: 		++$this->i;
   29: 		return parent::read($key);
   30: 	}
   31: }
   32: 
   33: class MySession4 extends MySession3 {
   34: 	public function write($id, $data) {
   35: 		$this->i = "hai";
   36: 		return parent::write($id, $data);
   37: 	}
   38: }
   39: 
   40: $handler = new MySession3;
   41: session_set_save_handler($handler);
   42: session_start();
   43: 
   44: $_SESSION['foo'] = "hello";
   45: 
   46: session_write_close();
   47: session_unset();
   48: 
   49: session_start();
   50: 
   51: var_dump($_SESSION, $handler->i);
   52: 
   53: session_write_close();
   54: session_unset();
   55: 
   56: $handler = new MySession4;
   57: session_set_save_handler($handler);
   58: 
   59: session_start();
   60: 
   61: session_write_close();
   62: session_unset();
   63: 
   64: var_dump(session_id(), $_SESSION, $handler->i);
   65: 
   66: --EXPECTF--
   67: *** Testing session_set_save_handler() : inheritance ***
   68: array(1) {
   69:   ["foo"]=>
   70:   string(5) "hello"
   71: }
   72: int(4)
   73: string(%d) "%s"
   74: array(1) {
   75:   ["foo"]=>
   76:   string(5) "hello"
   77: }
   78: string(3) "hai"

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>