php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #60957 if function returns false on error, don't emit a warning
Submitted: 2012-02-02 16:58 UTC Modified: 2016-08-26 13:49 UTC
Votes:4
Avg. Score:4.0 ± 1.7
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:2 (66.7%)
From: joel at purerave dot com Assigned:
Status: Open Package: Filesystem function related
PHP Version: Irrelevant 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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: joel at purerave dot com
New email:
PHP Version: OS:

 

 [2012-02-02 16:58 UTC] joel at purerave dot com
Description:
------------
functions that return FALSE on error should not also emit a warning.

Example: filemtime(). it is sufficient to check if the file exists and retrieve the mtime by doing:
if ($mtime = filemtime()) {
 echo date('ymd', $mtime);
} else {
 echo 'file does not exist';
}

supressing the warning with "@" is slow and generates an error in the log (also slow). checking if the file exists before retrieving the mtime is also wasteful.

Expected result:
----------------
filemtime and other functions that emit a warning on error when false is also returned should not emit a warning.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-02-04 17:16 UTC] php-dev at zerocue dot com
On my box with 54RC7, executing filemtime on a file that doesn't exist executing 
10,000 times takes 6.5 seconds, using the @ to suppress the error takes 0.058 
seconds so suppression with @ is pretty fast.  I'd say this is bogus.

If you're still logging the error with an @ because you have a custom error logger 
you can detect the use of the @ from within the error catch function.
 [2012-02-15 19:33 UTC] developer at suomedia dot com
This is an issue that really needs a rethink by the PHP devs - other functions suffer the same problem, for example:

get_headers()
file_get_contents()

Both of these functions also should return "false" on failure, however
if error reporting / warning is enabled they return a big phat WARNING.

This is just wrong - they should still just return "false" as they are supposed to.  Using @ to suppress errors is just an ugly hack and requires more code to handle what should be a very simple "false".
 [2016-08-26 13:49 UTC] cmb@php.net
In my opinion, these functions should thrown an exception instead
of returning FALSE and/or raising a warning. That would, however,
be a major BC break.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Nov 25 10:01:32 2024 UTC