#36034 [Opn->Bgs]: Order of destructor calls seems wrong.
| From: | sniper@php.net | Date: | Mon, 16 Jan 2006 22:27:44 +0000 |
| Subject: | #36034 [Opn->Bgs]: Order of destructor calls seems wrong. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-92026@lists.php.net to get a copy of this message | ||
ID: 36034
Updated by: sniper@php.net
Reported By: ian_c_web at thejolly dot demon dot co dot uk
-Status: Open
+Status: Bogus
Bug Type: Scripting Engine problem
Operating System: NetBSD
PHP Version: 5.1.2
New Comment:
Come up with a real script first. No bug here, you're trying to assing
a non existing variable. Ever heard about "error_reporting(E_ALL);" ??
Previous Comments:
------------------------------------------------------------------------
[2006-01-16 23:04:17] ian_c_web at thejolly dot demon dot co dot uk
The bug is nothing to do with databases, it infact occured as I was
trying to correctly close a result set.
The issue is with an object being destroyed when still referenced. If
you take a look at the example I provided you will see there is no
database code involved, however the destructors are still not called in
the expected order. (The 'Database' object's destructor is called whilst
it is still referenced by the 'Recordset' object.)
Please note the names I have used are purely semantic, there is no
actual database code involved.
------------------------------------------------------------------------
[2006-01-16 18:48:55] tony2001@php.net
The engine doesn't know about "result sets" and "database objects", all
it knows is that they are objects and they should be destroyed, so it's
your responsibility to call resultset destructors before database
destructors.
No bug here, this is expected behaviour.
------------------------------------------------------------------------
[2006-01-16 17:18:47] ian_c_web at thejolly dot demon dot co dot uk
Description:
------------
I have a class that abstracts a database connection, which returns a
'recordset' class for certain operations.
The destructor of the recordset class calls the necessary free
functions, which were issuing a 'warning: connection closed', which
turned out to be related to the database object going out of scope
first, and having it's destructor called. So I added a pointer to the
database in the recordset, thinking this would keep the database in
scope until the recordset was destroyed, but this did not seem to work.
If I assigned the recordset to null (hence forcing destruction)
everything works as required.
I think this is a scoping issue within PHP itself, as it seems to be
calling the destructor on the db object too early, although it doesn't
seem to actually be destroying the object. (I can still refer to public
variables within the object.)
Reproduce code:
---------------
http://thejolly.demon.co.uk/~ian/phptest.php.txt
Expected result:
----------------
SpecificApp construct.
Application construct.
Database construct. (test: 5)
ResultSet construct.
ResultSet destruct.
Database destruct. (test: 34)
Application destruct.
Actual result:
--------------
SpecificApp construct.
Application construct.
Database construct. (test: 5)
ResultSet construct.
Application destruct.
Database destruct. (test: 34)
ResultSet destruct.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=36034&edit=1