php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50154 session_set_save_handler can't get global variable(instance of object)
Submitted: 2009-11-12 07:16 UTC Modified: 2009-11-12 08:29 UTC
From: 0809 at 21cn dot com Assigned:
Status: Not a bug Package: Session related
PHP Version: 5.3.0 OS: linux as4
Private report: No CVE-ID: None
 [2009-11-12 07:16 UTC] 0809 at 21cn dot com
Description:
------------
hi staff,
  In my programs of  my php5.3,i use function "session_set_save_handler" to set the sessions into database,this function must set the parameters:names of the functions like :(open,close,read,write,destroy,gc) as string.
  when i use the functions :read,write,destroy,gc ,i set a global variable(an instance of object) in them ,but i found it works normally in these functions except in "write";i cann't get the value of the variable,only appears in the "wirte" function.
  i change the version of php to < 5.3 like :4.x ??5.2, the problem above disappears.
  i don't know the reason.can you help me to find it out?

  jjjackie

Reproduce code:
---------------
ini_set('session.save_handler', 'user');
class a{
var $var_a = 'here';
function a(){
}
}
$v = new a();
function open($save_path,$session_name){	return true;}
function close(){	return true;}
function read($id){	return true;}
function write($id,$value){
	global $v;
	echo($v ->var_a);
}
function destroy($id){ return true; }
function gc(){ return true; }
session_set_save_handler('open','close','read','write','destroy','gc');
session_start();

Expected result:
----------------
here

Actual result:
--------------
Notice: Trying to get property of non-object in /home/wwwroot/dgunion/inc/inc.session.php on line 182 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-11-12 08:29 UTC] jani@php.net
RTFM:

http://www.php.net/manual/en/function.session-set-save-handler.php

"As of PHP 5.0.5 the write  and close  handlers are called after object destruction and therefore cannot use objects or throw exceptions. The object destructors can however use sessions.

It is possible to call session_write_close() from the destructor to solve this chicken and egg problem."

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 13:01:30 2024 UTC