#30267 [Com]: fwrite() won't work properly in destructor

From: Date: Wed, 29 Sep 2004 22:48:42 +0000
Subject: #30267 [Com]: fwrite() won't work properly in destructor
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-66903@lists.php.net to get a copy of this message
ID: 30267 Comment by: htmldoug at msn dot com Reported By: eiriksletteberg at hotmail dot com Status: Open Bug Type: Zend Engine 2 problem Operating System: Windows 98SE PHP Version: 5.0.1 New Comment: Reproduction code run using PHP 5.0.2 under WinXP executes exactly as expected. Previous Comments: ------------------------------------------------------------------------ [2004-09-28 21:31:16] eiriksletteberg at hotmail dot com 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 this bug report at http://bugs.php.net/?id=30267&edit=1

« previous php.bugs (#66903) next »