#41755 [Opn->Csd]: clearstatcache() documentation needs to be updated
| From: | vrana@php.net | Date: | Thu, 16 Aug 2007 14:04:23 +0000 |
| Subject: | #41755 [Opn->Csd]: clearstatcache() documentation needs to be updated | ||
| References: | 1 | Groups: | php.doc |
| Request: | Send a blank email to phpdoc+get-969377507@lists.php.net to get a copy of this message | ||
ID: 41755
Updated by: vrana@php.net
Reported By: mahesh dot vemula at in dot ibm dot com
-Status: Open
+Status: Closed
Bug Type: Documentation problem
Operating System: Linux and Windows
PHP Version: PHP5
New Comment:
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.
Thank you for the report, and for helping us make our documentation
better.
"However unlink clears cache automatically."
Previous Comments:
------------------------------------------------------------------------
[2007-06-21 10:57:39] mahesh dot vemula at in dot ibm dot com
The bug is tested on php5 and php6
------------------------------------------------------------------------
[2007-06-21 08:54:02] mahesh dot vemula at in dot ibm dot com
Description:
------------
clearstatcache() documentation page:
http://in2.php.net/manual/en/function.clearstatcache.php
says "if you call file_exists() on a file that doesn't exist, it will
return FALSE until you create the file. If you create the file, it will
return TRUE even if you then delete the file.".
But if we delete the file using unlink(), and then use file_exists()
function on the file it returns FALSE, which contradicts with the
documentation of clearstatcache(), according to which it should return
TRUE even if you delete the file.
Samething happening with is_file(), is_dir() functions also.
Note:
From unlink() source code, we see that clearstarcache() gets internally
called with call to unlink() thus clearing the cache eachtime. Hence the
actual output seems to be correct, and the documentation needs to be
fixed.
For reference:
Source code of unlink() :
static int php_plain_files_unlink(php_stream_wrapper *wrapper, char
*url, int options, php_stream_context *context TSRMLS_DC)
{
char *p;
int ret;
zval funcname;
zval *retval = NULL;
if ((p = strstr(url, "://")) != NULL) {
url = p + 3;
}
if (options & ENFORCE_SAFE_MODE) {
if (PG(safe_mode) && !php_checkuid(url, NULL,
CHECKUID_CHECK_FILE_AND_DIR)) {
return 0;
}
if (php_check_open_basedir(url TSRMLS_CC)) {
return 0;
}
}
ret = VCWD_UNLINK(url);
if (ret == -1) {
if (options & REPORT_ERRORS) {
php_error_docref1(NULL TSRMLS_CC, url, E_WARNING, "%s",
strerror(errno));
}
return 0;
}
/* Clear stat cache */
ZVAL_STRINGL(&funcname, "clearstatcache", sizeof("clearstatcache")-1,
0);
call_user_function_ex(CG(function_table), NULL, &funcname, &retval, 0,
NULL, 0, NULL TSRMLS_CC);
if (retval) {
zval_ptr_dtor(&retval);
}
return 1;
}
Reproduce code:
---------------
<?php
fclose(fopen("temp.txt", "w"));
var_dump(file_exists("temp.txt"));
unlink("temp.txt");
var_dump(file_exists("temp.txt"));
?>
Expected result:
----------------
bool(true)
bool(false)
Actual result:
--------------
bool(true)
bool(false)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=41755&edit=1