php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16830 file_exists("") returns TRUE instead of FALSE
Submitted: 2002-04-25 15:57 UTC Modified: 2002-05-15 21:08 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: soeren dot fleischer at gmx dot net Assigned:
Status: Closed Package: Filesystem function related
PHP Version: 4.3.0-dev OS: ANY
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: soeren dot fleischer at gmx dot net
New email:
PHP Version: OS:

 

 [2002-04-25 15:57 UTC] soeren dot fleischer at gmx dot net
file_exists("") returns TRUE instead of FALSE.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-04-25 16:14 UTC] tal@php.net
Not enough information was provided for us to be able
to handle this bug. Please re-read the instructions at
http://bugs.php.net/how-to-report.php

If you can provide more information, feel free to add it
to this bug and change the status back to "Open".



 [2002-04-25 16:39 UTC] soeren dot fleischer at gmx dot net
file_exists("") returns TRUE instead of FALSE

As per request, here are more details...

This:
<?

$filename="";

if (is_file($filename))
{
print "is_file sais, the file $filename <b>does exist</b>.<br>";
}
else
{
print "is_file sais, the file $filename <b>did not exist</b>.<br>";
}


if (file_exists($filename))
{
print "file_exists sais, the file $filename <b>does exist</b>.<br>";
}
else
{
print "file_exists sais, the file $filename <b>did not exist</b>.<br>";
}

?>

will return:
is_file sais, the file did not exist.
file_exists sais, the file does exist.


Again, in other words:
If you give file_exists() an empty string as argument ( file_exists("") ), it will return TRUE (saying the file existed, but it does not, because "" is no file.)

is_file() correctly returns FALSE if you give it an empty string as argument and so should file_exists do, as it did in PHP 4.1.2


Further information:
I used to check my upload-scripts for uploaded files using $file=$_FILES['datei']['tmp_name'];
if (file_exists($file)) { savefile($file); }
but I cannot use this anymore because when a user does not upload a file, $filename becomes an empty string and file_exists returns TRUE, so my function savefile($file) wants to save a non-uploaded file.
 [2002-04-26 11:59 UTC] sander@php.net
Plese, SEARCH the bugdb. There is a report about this. (sorry Jani ;)
 [2002-04-26 12:47 UTC] soeren dot fleischer at gmx dot net
Sander, please tell me the Bug ID for it.

I did search the Bugs DB for open bugs with "file_exists".
The bug I'm talking about was reported as bug for PHP 4.1.0 ( Bug ID: 15218 ) and it has actually been fixed in 4.1.2, but now it appeared again in PHP 4.2.0 !!
So this is no duplicate bugreport, I think.
 [2002-04-26 22:11 UTC] sniper@php.net
Just in case..are you absolutely sure you have updated
all dlls related to PHP in your system? (I assume you had
some older PHP there before)

e.g. php4ts.dll is quite important to be new. Try searching
your filesystem for it. You might have many of them there.

--Jani

 [2002-04-27 00:27 UTC] soeren dot fleischer at gmx dot net
c:\winnt\system32\php4ts.dll matches the php4ts.dll from the php 4.2.0 package. All other PHP files are in php's own directory. When I install a new version of PHP, I always delete the whole old PHP directory and create a new one to prevent keeping rests from old versions. I also always use the new php.ini-dist and modify it again instead of keeping the old php.ini.

Additionally, in the last PHP version I had installed (4.1.2), file_exists() DID work! It just stopped working with PHP 4.2.0, so I doubt that error could be from forgetting to overwrite old DLLs with new ones.

What does the script I posted before say for _you_, Jani?
 [2002-04-27 10:41 UTC] sniper@php.net
Duh. You're right, it's a bug. 

<?php

$filename="";

$bb = is_file($filename);
var_dump($bb);

$aa = file_exists($filename);
var_dump($aa);

?>

Outputs:

int(0)
bool(true)


--Jani

 [2002-04-27 13:09 UTC] cynic@php.net
Jani, the var_dump()s IMO show two bugs: the other is that is_file() returned int(0), while it's documented to be a bool type. could you check this too?

 [2002-04-27 19:57 UTC] yohgaki@php.net
Just curious, is this fixed?
(I was about to commit test case for this bug)

[yohgaki@dev HEAD]$ ./cli-php ext/standard/tests/file/003.inc 
bool(false)
bool(false)



 [2002-04-27 20:09 UTC] yohgaki@php.net
I added following test case (ext/standard/tests/file/003.phpt)

<?php

$filename="";

$bb = is_file($filename);
var_dump($bb);

$aa = file_exists($filename);
var_dump($aa);

$filename="php.ini-dist";

$bb = is_file($filename);
var_dump($bb);

$aa = file_exists($filename);
var_dump($aa);

?>

Result:
[yohgaki@dev HEAD]$ cat ext/standard/tests/file/003.out
bool(false)
bool(false)
int(1)
bool(true)


 [2002-04-27 20:39 UTC] cynic@php.net
something stinks here:

[2002-04-27 10:41:44] sniper@php.net          

$filename="";
$bb = is_file($filename);
var_dump($bb);                                                          

int(0)

yohgaki:

$filename="";
           
$bb = is_file($filename);
var_dump($bb);                                                          

bool(false)  


so does is_file() return false or 0? plus it returned int(1) for you,
which it shouldn't either (should return bool(true) instead). WTF?


 [2002-05-15 21:08 UTC] sniper@php.net
This bug has been fixed in CVS. You can grab a snapshot of the
CVS version at http://snaps.php.net/. In case this was a documentation 
problem, the fix will show up soon at http://www.php.net/manual/.
In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites.
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 10:01:32 2024 UTC