From:             eiriksletteberg at hotmail dot com
Operating system: Windows 98SE
PHP version:      5.0.1
PHP Bug Type:     Zend Engine 2 problem
Bug description:  fwrite() won't work properly in destructor

Description:
------------
When this code is executed, one would expect data.txt
to contain "Hello World!". And, as file_get_contents() says,
it is. But when the script is completely executed, data.txt
does not contain "Hello World!" as it should. The
error does not occur if the destructor is called before
the script ends, eg. by unset()'ing $foo. Seems
like the destructor cannot write to files when called
at the end of scripts?!?

Reproduce code:
---------------
<?php
class data
{
   function __destruct()
   {
       $data = "Hello World!";

       // Show that the destructor is called
       print "Destructor called.";

       $link = fopen("data.txt", 'w');
       fwrite($link, $data);
       fclose($link);
       
       // Check if we have written it
       print "Contents: ".file_get_contents("data.txt");
   }
}
$foo = new data;
?>

Expected result:
----------------
data.txt should contain "Hello World!"

Actual result:
--------------
data.txt is empty or contains the previous value

-- 
Edit bug report at http://bugs.php.net/?id=30267&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=30267&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=30267&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=30267&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=30267&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=30267&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=30267&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=30267&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=30267&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=30267&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=30267&r=notwrong
Not enough info:             http://bugs.php.net/fix.php?id=30267&r=notenoughinfo
Submitted twice:             http://bugs.php.net/fix.php?id=30267&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=30267&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=30267&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=30267&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=30267&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=30267&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=30267&r=float
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=30267&r=mysqlcfg

Reply via email to