ID: 42626 Comment by: admin at tifyouwantblood dot de Reported By: admin at ifyouwantblood dot de Status: Open Bug Type: Class/Object related Operating System: Windows XP SP2 PHP Version: 5.2.4 New Comment:
this works as expected on PHP 5.2.2 on SunOS. Previous Comments: ------------------------------------------------------------------------ [2007-09-11 19:18:08] admin at ifyouwantblood dot de Description: ------------ Calling clearstatcache() in destructor causes some very weird stuff. In the code below a file is created / truncated in the constructor. If you want to read the same file with fread in the destructor while it's still empty i'm expecting fread to print an error which it does. However if you write something to the file AFTER reading it and run the script twice fread returns what's written before. This should not happen, because before reading the file, we truncate it. Moreover if you continue calling the script, the string that fread returns contains all the writing operations done before. The strangest thing is, that it looks like that this behavior got something to do with the filename "datei.txt" (is German, means file.txt). If you change the filename, the fopen($this->filename,'r+') after clearstatcache() fails with the error "file does not exists". If you explicite truncate the file before reading it with ftruncate() no error is printed. If you remove clearstatcache() in the destructor it works as expected. This also appears on PHP 5.2.3 Reproduce code: --------------- <pre> <?php #call this script more than once! error_reporting(E_ALL|E_NOTICE); $test=new test; class test { private $filename='datei.txt'; public function __construct() { # open and truncate $file=fopen($this->filename,'w'); fclose($file); echo 'filesize after truncate: '.filesize($this->filename)."\n"; } public function __destruct() { echo 'Destructing test'."\n"; echo 'filesize before clearstatcache: '.filesize($this->filename)."\n"; clearstatcache(); echo 'filesize after clearstatcache: '.filesize($this->filename)."\n"; $file=fopen($this->filename,'r+'); if($file) { echo 'Reading file: '.fread($file,filesize($this->filename)); fputs($file,'aasadf'); } } } ?> Expected result: ---------------- filesize after truncate: 0 Destructing test filesize before clearstatcache: 0 filesize after clearstatcache: 0 Warning: fread() [function.fread]: Length parameter must be greater than 0 in G:\php\htdocs\cms\1jailbreak\admin\constructor.php on line 34 Reading file: Actual result: -------------- filesize after truncate: 0 Destructing test filesize before clearstatcache: 0 filesize after clearstatcache: 6 Reading file: aasadf ----- on repeated calling: filesize after truncate: 0 Destructing test filesize before clearstatcache: 0 filesize after clearstatcache: 12 Reading file: aasadfaasadf ----- filesize after truncate: 0 Destructing test filesize before clearstatcache: 0 filesize after clearstatcache: 18 Reading file: aasadfaasadfaasadf and so on... ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=42626&edit=1