php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #22398 file_exists returns TRUE when given a null filename
Submitted: 2003-02-24 12:26 UTC Modified: 2003-02-25 02:57 UTC
From: alan at frostick dot com Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 4.3.1 OS: WIN32
Private report: No CVE-ID: None
 [2003-02-24 12:26 UTC] alan at frostick dot com
Filesystem function: file_exists() return value (PHP_VERSION='4.3.1', PHP_OS='WIN32')

file_exists() returns TRUE if it is passed a null string or an undefined variable.
e.g. 	file_exists("");	// returns TRUE

Previously it always returned FALSE (at least it did in PHP3).

Is that a bug or a change of definition? If so it is undocumented. The rsult is also inconsistent with that returned by is_file() in this case, as my example below demonstrates.

I note this is a similar report to apparently "bogus" #19934. Perhaps this will convince you?
Example script:
As given in Manual\function.file-exists.html (modified to demonstrate the above fault):

<?php
$filename = '';

print "<BR>file_exists: ";
if (file_exists($filename)) {
    print "The file $filename exists";
} else {
    print "The file $filename does not exist";
}

print "<BR>is_file: ";
if (is_file($filename)) {
    print "The file $filename exists";
} else {
    print "The file $filename does not exist";
}

?>

Result is:
file_exists: The file exists
is_file: The file does not exist

I also tried it with unset($filename) instead of a null string assignment in the above, and get the same result.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-02-25 02:57 UTC] sniper@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. Because of this, we hope you add your comments
to the existing bug instead.

Thank you for your interest in PHP.

See bug #21410

 [2003-02-25 13:49 UTC] alan at frostick dot de
Nice of you to add this problem as a note on a previously unrelated bug AFTER my report went in... and then claim I failed to check.

#21410 was previously a report for 4.3.0, not for the currently released 4.3.1 and as I remember it appeared to be put down to a documentation problem and was not OPEN. I see now it has retrospectively been assigned the status "verfied" for 4.3.2-dev AFTER I entered this report.

Of course I checked first, I spent about half an hour doing so before reporting, painstakingly going through many similar reports. I concluded that this problem was just being ignored by you and a succinct report of the problem was well overdue. To claim my report maliciously ignored existing open bug reports is not only false, but I feel your comments are unwarranted.

Forget it in future... no more time-consuming research and documenting of problems by me. I'll keep quiet about bugs from here on in and wish no further contact with you guys.

OVER and OUT.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Sep 18 19:01:28 2024 UTC