Grokbase Groups PHP php-doc June 2007
FAQ
From: mahesh dot vemula at in dot ibm dot com
Operating system: Linux and Windows
PHP version: Irrelevant
PHP Bug Type: Documentation problem
Bug description: clearstatcache() documentation needs to be updated

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)

Search Discussions

  • Mahesh dot vemula at in dot ibm dot com at Jun 21, 2007 at 10:57 am
    ID: 41755
    User updated by: mahesh dot vemula at in dot ibm dot com
    Reported By: mahesh dot vemula at in dot ibm dot com
    Status: Open
    Bug Type: Documentation problem
    Operating System: Linux and Windows
    -PHP Version: Irrelevant
    +PHP Version: PHP5
    New Comment:

    The bug is tested on php5 and php6


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

    [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
  • Vrana at Aug 17, 2007 at 3:14 am
    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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupphp-doc @
categoriesphp
postedJun 21, '07 at 8:54a
activeAug 17, '07 at 3:14a
posts3
users2
websitedoc.php.net

People

Translate

site design / logo © 2018 Grokbase