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".