note 91008 deleted from function.file-exists by cmb
| From: | cmb@php.net | Date: | Sun, 29 Sep 2019 07:12:33 +0000 |
| Subject: | note 91008 deleted from function.file-exists by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-212377@lists.php.net to get a copy of this message | ||
Note Submitter: jbeltran
----
I want to warn developers using PHP 5.0.4 of a bug that don't happen in current stable
versions:
file_exists seems to cache the response, even when the file has been moved.
An example:
<?php
/*
When a file which has been called by file_exist
has been moved, the file_exist next call gives true again
*/
$f = "foo.txt";
file_put_contents( $f, "content" );
if(file_exists( $f )){
rename( $f, $f.".moved" );
}
if( file_exists( $f )){
echo "Wrong! the file has just been moved! file_exists should return false.";
rename( $f, $f.".willnotwork" ); //It gives a warning
}
?>
The same code tested in PHP 5.2.4-2ubuntu5.6 with Suhosin-Patch 0.9.6.2 (cli) behaves correctly.