|  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
 [2006-11-13 09:29 UTC] zeke at cs-cart dot com
I think its related with

"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:

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

class my_mysqli extends mysqli {
	public function __destruct(){

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


Expected result:
In php 5 prior 5.2.0 displays:


Actual result:
In php 5.2.0 displays:



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-13 09:50 UTC]
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: Thu Feb 29 16:01:38 2024 UTC