php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #41755 clearstatcache() documentation needs to be updated
Submitted: 2007-06-21 08:54 UTC Modified: 2007-08-16 14:04 UTC
From: mahesh dot vemula at in dot ibm dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: PHP5 OS: Linux and Windows
Private report: No CVE-ID: None
 [2007-06-21 08:54 UTC] 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)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-06-21 10:57 UTC] mahesh dot vemula at in dot ibm dot com
The bug is tested on php5 and php6
 [2007-08-16 14:04 UTC] vrana@php.net
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."
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 16:01:31 2024 UTC