|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-07-14 23:53 UTC] kaspersv at privat dot dk
[2004-07-19 20:19 UTC] riorius at hotmail dot com
[2004-08-05 23:28 UTC] edink@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Dec 04 16:00:01 2025 UTC |
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.