php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30267 fwrite() won't work properly in destructor
Submitted: 2004-09-28 21:31 UTC Modified: 2004-10-08 01:01 UTC
Votes:3
Avg. Score:4.0 ± 0.8
Reproduced:2 of 3 (66.7%)
Same Version:2 (100.0%)
Same OS:0 (0.0%)
From: eiriksletteberg at hotmail dot com Assigned:
Status: No Feedback Package: Scripting Engine problem
PHP Version: 5.0.1 OS: Windows 98SE
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
48 + 50 = ?
Subscribe to this entry?

 
 [2004-09-28 21:31 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-09-30 00:48 UTC] htmldoug at msn dot com
Reproduction code run using PHP 5.0.2 under WinXP executes exactly as expected.
 [2004-09-30 03:34 UTC] iliaa@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-STABLE-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.0-win32-latest.zip

Cannot replicate on either windows or linux.
 [2004-10-08 01:01 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 15:01:30 2024 UTC