From: riorius at hotmail dot com
Operating system: Windows 2000 Pro
PHP version: 5.0.0
PHP Bug Type: Class/Object related
Bug description: Odd behavior when opening a file from __destruct()
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 bug report at http://bugs.php.net/?id=29164&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=29164&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=29164&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=29164&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=29164&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=29164&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=29164&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=29164&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=29164&r=support
Expected behavior: http://bugs.php.net/fix.php?id=29164&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=29164&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=29164&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=29164&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=29164&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=29164&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=29164&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=29164&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=29164&r=float