File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / session / tests / 025.phpt
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue Feb 21 23:48:01 2012 UTC (12 years, 4 months 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, v5_3_10, HEAD
php

    1: --TEST--
    2: custom save handler, multiple session_start()s, complex data structure test.
    3: --SKIPIF--
    4: <?php include('skipif.inc'); ?>
    5: --INI--
    6: session.use_cookies=0
    7: session.cache_limiter=
    8: session.name=PHPSESSID
    9: session.serialize_handler=php
   10: --FILE--
   11: <?php
   12: 
   13: error_reporting(E_ALL);
   14: 
   15: class handler {
   16:     public $data = 'baz|O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";i:1;}arr|a:1:{i:3;O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";i:1;}}';
   17: 
   18:     function open($save_path, $session_name)
   19:     {
   20:         print "OPEN: $session_name\n";
   21:         return true;
   22:     }
   23:     function close()
   24:     {
   25: 		print "CLOSE\n";
   26:         return true;
   27:     }
   28:     function read($key)
   29:     {
   30:         print "READ: $key\n";
   31:         return $GLOBALS["hnd"]->data;
   32:     }
   33: 
   34:     function write($key, $val)
   35:     {
   36:         print "WRITE: $key, $val\n";
   37:         $GLOBALS["hnd"]->data = $val;
   38:         return true;
   39:     }
   40: 
   41:     function destroy($key)
   42:     {
   43:         print "DESTROY: $key\n";
   44:         return true;
   45:     }
   46: 
   47:     function gc() { return true; }
   48: 
   49:     function __construct()
   50:     {
   51:         if (ini_get("unicode.semantics")) {
   52:             $this->data = str_replace('s:', 'U:', $this->data);
   53:         }
   54:     }
   55: }
   56: 
   57: $hnd = new handler;
   58: 
   59: class foo {
   60:     public $bar = "ok";
   61:     function method() { $this->yes++; }
   62: }
   63: 
   64: session_set_save_handler(array($hnd, "open"), array($hnd, "close"), array($hnd, "read"), array($hnd, "write"), array($hnd, "destroy"), array($hnd, "gc"));
   65: 
   66: session_id("abtest");
   67: session_start();
   68: $baz = $_SESSION['baz'];
   69: $arr = $_SESSION['arr'];
   70: $baz->method();
   71: $arr[3]->method();
   72: 
   73: var_dump($baz);
   74: var_dump($arr);
   75: 
   76: session_write_close();
   77: 
   78: session_set_save_handler(array($hnd, "open"), array($hnd, "close"), array($hnd, "read"), array($hnd, "write"), array($hnd, "destroy"), array($hnd, "gc"));
   79: session_start();
   80: $baz = $_SESSION['baz'];
   81: $arr = $_SESSION['arr'];
   82: 
   83: 
   84: $baz->method();
   85: $arr[3]->method();
   86: 
   87: 
   88: $c = 123;
   89: $_SESSION['c'] = $c;
   90: var_dump($baz); var_dump($arr); var_dump($c);
   91: 
   92: session_write_close();
   93: 
   94: session_set_save_handler(array($hnd, "open"), array($hnd, "close"), array($hnd, "read"), array($hnd, "write"), array($hnd, "destroy"), array($hnd, "gc"));
   95: session_start();
   96: var_dump($baz); var_dump($arr); var_dump($c);
   97: 
   98: session_destroy();
   99: ?>
  100: --EXPECTF--
  101: OPEN: PHPSESSID
  102: READ: abtest
  103: object(foo)#%d (2) {
  104:   ["bar"]=>
  105:   string(2) "ok"
  106:   ["yes"]=>
  107:   int(2)
  108: }
  109: array(1) {
  110:   [3]=>
  111:   object(foo)#%d (2) {
  112:     ["bar"]=>
  113:     string(2) "ok"
  114:     ["yes"]=>
  115:     int(2)
  116:   }
  117: }
  118: WRITE: abtest, baz|O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";i:2;}arr|a:1:{i:3;O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";i:2;}}
  119: CLOSE
  120: OPEN: PHPSESSID
  121: READ: abtest
  122: object(foo)#%d (2) {
  123:   ["bar"]=>
  124:   string(2) "ok"
  125:   ["yes"]=>
  126:   int(3)
  127: }
  128: array(1) {
  129:   [3]=>
  130:   object(foo)#%d (2) {
  131:     ["bar"]=>
  132:     string(2) "ok"
  133:     ["yes"]=>
  134:     int(3)
  135:   }
  136: }
  137: int(123)
  138: WRITE: abtest, baz|O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";i:3;}arr|a:1:{i:3;O:3:"foo":2:{s:3:"bar";s:2:"ok";s:3:"yes";i:3;}}c|i:123;
  139: CLOSE
  140: OPEN: PHPSESSID
  141: READ: abtest
  142: object(foo)#%d (2) {
  143:   ["bar"]=>
  144:   string(2) "ok"
  145:   ["yes"]=>
  146:   int(3)
  147: }
  148: array(1) {
  149:   [3]=>
  150:   object(foo)#%d (2) {
  151:     ["bar"]=>
  152:     string(2) "ok"
  153:     ["yes"]=>
  154:     int(3)
  155:   }
  156: }
  157: int(123)
  158: DESTROY: abtest
  159: CLOSE

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