From:             ian_c_web at thejolly dot demon dot co dot uk
Operating system: NetBSD
PHP version:      5.1.2
PHP Bug Type:     Scripting Engine problem
Bug description:  Order of destructor calls seems wrong.

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 bug report at http://bugs.php.net/?id=36034&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=36034&r=trysnapshot44
Try a CVS snapshot (PHP 5.1): 
http://bugs.php.net/fix.php?id=36034&r=trysnapshot51
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=36034&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=36034&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=36034&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=36034&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=36034&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=36034&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=36034&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=36034&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=36034&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=36034&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=36034&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=36034&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=36034&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=36034&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=36034&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=36034&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=36034&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=36034&r=mysqlcfg

Reply via email to