Edit report at https://bugs.php.net/bug.php?id=60957&edit=1
ID: 60957
Comment by: developer at suomedia dot com
Reported by: joel at purerave dot com
Summary: if function returns false on error, don't emit a
warning
Status: Open
Type: Feature/Change Request
Package: Filesystem function related
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
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".
Previous Comments:
------------------------------------------------------------------------
[2012-02-04 17:16:26] 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-02 16:58:24] 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.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=60957&edit=1