php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39491 MySQLi object destroys too early
Submitted: 2006-11-13 09:29 UTC Modified: 2006-11-13 12:03 UTC
From: zeke at cs-cart dot com Assigned:
Status: Not a bug Package: MySQLi related
PHP Version: 5.2.0 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: zeke at cs-cart dot com
New email:
PHP Version: OS:

 

 [2006-11-13 09:29 UTC] zeke at cs-cart dot com
Description:
------------
I think its related with 
http://bugs.php.net/bug.php?id=33772

========
"Write and Close handlers are called after destructing objects since PHP
5.0.5. Thus destructors can use sessions but session handler can't use
objects. In prior versions, they were called in the opposite order. It
is possible to call session_write_close() from the destructor to solve
this chicken and egg problem."
===========

It doesn't work since php 5.2.0.

Reproduce code:
---------------
<?php


function sess_save()
{
	global $db_conn;
	echo is_object($db_conn) ? "OK" : "FAIL";
}

class my_mysqli extends mysqli {
	public function __destruct(){
		sess_save();
	}
}



$db_conn = new my_mysqli($db_host, $db_user, $db_password);


?>


Expected result:
----------------
In php 5 prior 5.2.0 displays:

"OK"



Actual result:
--------------
In php 5.2.0 displays:

"FAIL"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-13 09:50 UTC] tony2001@php.net
It has nothing to do with the problem described in #33772.
Accessing object, which is being currently destroyed, through it's global reference is nonsense. And nobody guaranteed that this reference will exist at the moment where __destruct() is called.
Pass $this as an argument to sess_save().
 [2006-11-13 12:03 UTC] zeke at cs-cart dot com
===
Accessing object, which is being currently destroyed, through it's global reference is nonsense
===

But why? It's not destroyed yet! It's just preparing to be destroyed.

BTW. Could you please specify why this code worked on earlier versions?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 06:01:29 2024 UTC