#29164 [Com]: Odd behavior when opening a file from __destruct()
| From: | kaspersv at privat dot dk | Date: | Wed, 14 Jul 2004 21:53:12 +0000 |
| Subject: | #29164 [Com]: Odd behavior when opening a file from __destruct() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-62305@lists.php.net to get a copy of this message | ||
ID: 29164
Comment by: kaspersv at privat dot dk
Reported By: riorius at hotmail dot com
Status: Open
Bug Type: Class/Object related
Operating System: Windows 2000 Pro
PHP Version: 5.0.0
New Comment:
This bug is probably a variation of the same problem that I
experienced. Try changing the permissions for the apache-root folder
(e.g. C:\Program Files\Apache Group\Apache on my computer).
http://bugs.php.net/bug.php?id=29167
Previous Comments:
------------------------------------------------------------------------
[2004-07-14 22:08:50] riorius at hotmail dot com
Description:
------------
In my script, a user-defined class is instantiated, and a reference is
maintained until the script's end. When the script ends, the class's
__destruct() method is called. Inside of the __destruct() method for
this class, I was trying to open a file on the server to save data.
Reproduce code:
---------------
<?php
class Foo
{
function __destruct()
{
$out = fopen("save.txt", "w");
fwrite($out, $info);
}
}
$temp = new Foo();
?>
Expected result:
----------------
I expected that, when the script ended, the __destruct() method would
be called, and it would successfully open the file and save the data.
Actual result:
--------------
When opening a file for writing, I would get a warning, "failed to open
stream: Permission denied"; if I tried to open a file for reading, I
would get a different warning, "failed to open stream: No such file or
directory".
Neither of these errors are appropriate: all permissions were
available, the file was already created. If I used the exact same code
in another method, or destroyed the reference to the class before the
script's termination (thus causing the __destruct() method to be called
earlier), the file would open and write with no problems. This only
arose when the reference to my object was destroyed by the script's
termination.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=29164&edit=1