#22398 [Opn->Bgs]: file_exists returns TRUE when given a null filename

From: Date: Tue, 25 Feb 2003 08:57:17 +0000
Subject: #22398 [Opn->Bgs]: file_exists returns TRUE when given a null filename
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-34194@lists.php.net to get a copy of this message
ID: 22398 Updated by: sniper@php.net Reported By: alan at frostick dot com -Status: Open +Status: Bogus Bug Type: Filesystem function related Operating System: WIN32 PHP Version: 4.3.1 New Comment: 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 Previous Comments: ------------------------------------------------------------------------ [2003-02-24 12:26:48] 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. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=22398&edit=1

« previous php.bugs (#34194) next »