ID:               36034
 User updated by:  ian_c_web at thejolly dot demon dot co dot uk
 Reported By:      ian_c_web at thejolly dot demon dot co dot uk
-Status:           Bogus
+Status:           Open
 Bug Type:         Scripting Engine problem
 Operating System: NetBSD
 PHP Version:      5.1.2
 New Comment:

Oops, my cut and paste badness.

Still doesn't work as expected though, the 'Database' object is still
being destroyed first.

(Example script updated.)

PS, no, didn't know about 'error_reporting(E_ALL);', cheers, that will
be most useful.


Previous Comments:
------------------------------------------------------------------------

[2006-01-16 23:27:43] [EMAIL PROTECTED]

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);" ??


------------------------------------------------------------------------

[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] [EMAIL PROTECTED]

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

Reply via email to