ID:               42626
 User updated by:  admin at ifyouwantblood dot de
 Reported By:      admin at ifyouwantblood dot de
-Status:           Open
+Status:           Closed
 Bug Type:         Class/Object related
 Operating System: Windows XP SP2
 PHP Version:      5.2.4
 New Comment:

allright guys it should be mentioned somewhere that the destructor's
base directory is the root of the server. so this 'bug' is not a bug,
but a simple mistake which could have been avoided just by telling
this....

the given sample searches for the file in the base directory of the
server. unfortunatly i had had a file there with the name 'datei.txt'
which then was read by/written to by php.

but to my reassurance none of the developers seems to know this, or
else they would have said something, wouldn't they?

so, if any one ever reads this, where can i communicate with the PHP
Manual team in order to tell this (and something else)?

greetings.


Previous Comments:
------------------------------------------------------------------------

[2007-10-22 21:58:38] admin at ifyouwantblood dot de

hi,

now i get the following with windows 5.2.5RC2 build Oct 22 2007
12:03:56 althought the file exists (but with size 0):

--------------------------
filesize after truncate: 0
Destructing test
filesize before clearstatcache: 0

Warning:  filesize() [function.filesize]: stat failed for datei.txt in
F:\php\htdocs\ALL\bug.php on line 30
filesize after clearstatcache: 

Warning:  fopen(datei.txt) [function.fopen]: failed to open stream: No
such file or directory in F:\php\htdocs\ALL\bug.php on line 32
---------------------------

------------------------------------------------------------------------

[2007-10-22 11:23:01] [EMAIL PROTECTED]

Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows (zip):
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip

For Windows (installer):

  http://snaps.php.net/win32/php5.2-win32-installer-latest.msi



------------------------------------------------------------------------

[2007-09-12 00:14:41] admin at tifyouwantblood dot de

this works as expected on PHP 5.2.2 on SunOS.

------------------------------------------------------------------------

[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

Reply via email to