File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / session / tests / session_set_save_handler_class_010.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() : manual shutdown function
    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() : manual shutdown function ***\n";
   20: 
   21: class MySession extends SessionHandler {
   22: 	public $num;
   23: 	public function __construct($num) {
   24: 		$this->num = $num;
   25: 		echo "(#$this->num) constructor called\n";
   26: 	}
   27: 	public function __destruct() {
   28: 		echo "(#$this->num) destructor called\n";
   29: 	}
   30: 	public function finish() {
   31: 		$id = session_id();
   32: 		echo "(#$this->num) finish called $id\n";
   33: 		session_write_close();
   34: 	}
   35: 	public function write($id, $data) {
   36: 		echo "(#$this->num) writing $id = $data\n";
   37: 		return parent::write($id, $data);
   38: 	}
   39: 	public function close() {
   40: 		$id = session_id();
   41: 		echo "(#$this->num) closing $id\n";
   42: 		return parent::close();
   43: 	}
   44: }
   45: 
   46: $handler = new MySession(1);
   47: session_set_save_handler($handler, false);
   48: register_shutdown_function(array($handler, 'finish'));
   49: session_start();
   50: 
   51: $_SESSION['foo'] = 'bar';
   52: 
   53: echo "done\n";
   54: ob_end_flush();
   55: ?>
   56: --EXPECTF--
   57: *** Testing session_set_save_handler() : manual shutdown function ***
   58: (#1) constructor called
   59: done
   60: (#1) finish called %s
   61: (#1) writing %s = foo|s:3:"bar";
   62: (#1) closing %s
   63: (#1) destructor called

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