#29164 [Opn]: Odd behavior when opening a file from __destruct()
| From: | riorius at hotmail dot com | Date: | Mon, 19 Jul 2004 18:19:57 +0000 |
| Subject: | #29164 [Opn]: Odd behavior when opening a file from __destruct() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-62669@lists.php.net to get a copy of this message | ||
ID: 29164
User updated by: riorius at hotmail dot com
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:
Based on "kaspersv at privat dot dk"'s comment, I found a workaround.
Since the script tries to open a file in the apache root directory
rather than the script's directory, the solution is to specify the
entire path:
$out = fopen(dirname($_SERVER['PATH_TRANSLATED']) . "/save.txt", "w");
Previous Comments:
------------------------------------------------------------------------
[2004-07-14 23:53:11] kaspersv at privat dot dk
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
------------------------------------------------------------------------
[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