php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76364 filemtime() must return false if file not exist
Submitted: 2018-05-22 07:10 UTC Modified: 2018-05-22 07:32 UTC
From: golden dot pr at mail dot ru Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 7.1.17 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: golden dot pr at mail dot ru
New email:
PHP Version: OS:

 

 [2018-05-22 07:10 UTC] golden dot pr at mail dot ru
Description:
------------
---
From manual page: http://www.php.net/function.filemtime
---
filemtime() must return false if file not exist

Test script:
---------------
$path = './test.txt';
echo @filemtime($path);


Expected result:
----------------
filemtime(): stat failed for {$path}

Actual result:
--------------
false

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-05-22 07:11 UTC] golden dot pr at mail dot ru
Expected result:
----------------
false

Actual result:
--------------
filemtime(): stat failed for {$path}
 [2018-05-22 07:32 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2018-05-22 07:32 UTC] requinix@php.net
http://php.net/manual/en/language.types.string.php#language.types.string.casting

If you don't think the "Converting to string" section is relevant to your problem, read it again until it does.
 [2018-05-22 08:31 UTC] spam2 at rhsoft dot net
it does exactly what the docs say, the only thing which should be fixed is the braindead warning for functions which return false in case of errors so that you don't need @ or a uselss file_exists() around the code

you likely miss one of the most important facts when working with PHP: ===, !== when compare values and when boolean false is converted to a string it's an empty string, since echo is working with string it does implicit typecasting and false is something completly different then the string 'false'

php > echo false;
php >

php > if(filemtime('nonexists') === false){echo 'NON-EXISTS';}
Warning: filemtime(): stat failed for nonexists in php shell code on line 1
NON-EXISTS
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 06:01:28 2024 UTC