Bug #76364 [Com]: filemtime() must return false if file not exist

From: Date: Tue, 22 May 2018 08:31:16 +0000
Subject: Bug #76364 [Com]: filemtime() must return false if file not exist
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-215326@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76364&edit=1

 ID:                 76364
 Comment by:         spam2 at rhsoft dot net
 Reported by:        golden dot pr at mail dot ru
 Summary:            filemtime() must return false if file not exist
 Status:             Not a bug
 Type:               Bug
 Package:            Filesystem function related
 PHP Version:        7.1.17
 Block user comment: N
 Private report:     N

 New Comment:

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


Previous Comments:
------------------------------------------------------------------------
[2018-05-22 07:32:03] 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 07:11:44] golden dot pr at mail dot ru

Expected result:
----------------
false

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

------------------------------------------------------------------------
[2018-05-22 07:10:34] 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


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=76364&edit=1


Thread (4 messages)

« previous php.bugs (#215326) next »