From: richard dot quadling at bandvulc dot co dot uk
Operating system: Windows XP Pro SP2
PHP version: 5.0.2
PHP Bug Type: Class/Object related
Bug description: Objects destroyed in FIFO rather LIFO.
Description:
------------
Hi.
Create Object A (a action logging class)
Create Object B (a class which allows generates logging actions).
As each method in B is called a log entry is made by using an IN and OUT
method on A.
During the shutdown, the __destroy method of A is called (which closes the
log), then, the __destroy method of B is called. This method has the
logging code in it. This then tries to call a destroyed object.
As you cannot refer to an object until it is created, you should always
destroy objects in the reverse order in which they were created.
Richard.
Reproduce code:
---------------
<?php
class A
{
public function __construct()
{
echo 'Constructing A<br />';
}
public function __destruct()
{
echo 'Destroying A<br />';
}
public function Logging($sLog)
{
echo date('r') . ' '. $sLog . '<br />';
}
}
class B
{
public function __construct()
{
$GLOBALS['objLogger']->Logging(__METHOD__ . ' ' . __FILE__ . '
' .
__LINE__);
}
public function __destruct()
{
$GLOBALS['objLogger']->Logging(__METHOD__ . ' ' . __FILE__ . '
' .
__LINE__);
}
public function Action()
{
$GLOBALS['objLogger']->Logging(__METHOD__ . ' ' . __FILE__ . '
' .
__LINE__);
}
}
$objLogger = new A();
$objAction = new B();
$objAction->Action();
?>
Expected result:
----------------
Constructing A
Thu, 18 Nov 2004 09:51:07 +0000 B::__construct D:\Data\Web Sites\Quick
Scripts\public_html\PHP Bug testing\Objects destroyed FIFO.php 24
Thu, 18 Nov 2004 09:51:07 +0000 B::Action D:\Data\Web Sites\Quick
Scripts\public_html\PHP Bug testing\Objects destroyed FIFO.php 34
Thu, 18 Nov 2004 09:51:07 +0000 B::__destruct D:\Data\Web Sites\Quick
Scripts\public_html\PHP Bug testing\Objects destroyed FIFO.php 29
Destroying A
Actual result:
--------------
Constructing A
Thu, 18 Nov 2004 09:51:07 +0000 B::__construct D:\Data\Web Sites\Quick
Scripts\public_html\PHP Bug testing\Objects destroyed FIFO.php 24
Thu, 18 Nov 2004 09:51:07 +0000 B::Action D:\Data\Web Sites\Quick
Scripts\public_html\PHP Bug testing\Objects destroyed FIFO.php 34
Destroying A
Thu, 18 Nov 2004 09:51:07 +0000 B::__destruct D:\Data\Web Sites\Quick
Scripts\public_html\PHP Bug testing\Objects destroyed FIFO.php 29
--
Edit bug report at http://bugs.php.net/?id=30823&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=30823&r=trysnapshot4
Try a CVS snapshot (php5.0):
http://bugs.php.net/fix.php?id=30823&r=trysnapshot50
Try a CVS snapshot (php5.1):
http://bugs.php.net/fix.php?id=30823&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=30823&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=30823&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=30823&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=30823&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=30823&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=30823&r=support
Expected behavior: http://bugs.php.net/fix.php?id=30823&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=30823&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=30823&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=30823&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=30823&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=30823&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=30823&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=30823&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=30823&r=float
MySQL Configuration Error: http://bugs.php.net/fix.php?id=30823&r=mysqlcfg