note 124444 added to function.file-get-contents
| From: | SergeyPodgornyy@php.net | Date: | Wed, 27 Nov 2019 11:23:40 +0000 |
| Subject: | note 124444 added to function.file-get-contents | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-213267@lists.php.net to get a copy of this message | ||
file_get_contents() could throws an ErrorException, but isn't documented.
I found it only for case, when file name is empty:
Warning: file_get_contents(): Filename cannot be empty
Of course, for this specific case if could be prevented by checking string:
<?php
if (empty($fileName)) {
throw new \LogicException('File name could not be empty');
}
$fileContent = \file_get_contents($fileName);
?>
But as it is not described in the documentation which Exceptions and in which cases could be thrown,
it is forcing people like me to use outdated @ operator, or wrap all code execution with catch
(\Throwable $e)
----
Server IP: 208.43.231.9
Probable Submitter: 185.85.3.168 (proxied: 80.81.11.107)
----
Manual Page -- http://php.net/manual/en/function.file-get-contents.php
Edit -- https://master.php.net/note/edit/124444
Del: integrated -- https://master.php.net/note/delete/124444/integrated
Del: useless -- https://master.php.net/note/delete/124444/useless
Del: bad code -- https://master.php.net/note/delete/124444/bad+code
Del: spam -- https://master.php.net/note/delete/124444/spam
Del: non-english -- https://master.php.net/note/delete/124444/non-english
Del: in docs -- https://master.php.net/note/delete/124444/in+docs
Del: other reasons-- https://master.php.net/note/delete/124444
Reject -- https://master.php.net/note/reject/124444
Search -- https://master.php.net/manage/user-notes.php