php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81035 file_get_contents emits not silenceable warning on http file not exists
Submitted: 2021-05-12 09:46 UTC Modified: 2021-05-12 10:00 UTC
From: shop1 at mokraemer dot de Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 8.0.6 OS: linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
19 - 2 = ?
Subscribe to this entry?

 
 [2021-05-12 09:46 UTC] shop1 at mokraemer dot de
Description:
------------
file_get_contents emits a warning instead of an exception if the file does not exist!

This may be a good choice if the file is local where you can test for file existence. In case of remote files via http, this is quite not possible.

Since the silence operator does not work anymore, this raises undesireable errors in the logs.

Test script:
---------------
file_get_contents('https://www.google.com/rss.xml');

Expected result:
----------------
do not emit warnings. Just throw exceptions!

Actual result:
--------------
the emitted warning is filling the logs and does not help!

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-05-12 09:54 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2021-05-12 09:54 UTC] nikic@php.net
You may wish to either suppress the warning using "@" (if you do not care about it), or promote it to an exception using an error handler. The existing behavior will not be changed for backwards-compatibility reasons.
 [2021-05-12 09:56 UTC] shop1 at mokraemer dot de
the @ operator does not work as it does in php 7.4
 [2021-05-12 10:00 UTC] nikic@php.net
The @ operator no longer suppresses fatal errors in PHP 8. It does still suppress warnings, and file_get_contents() throws a warning, not a fatal error.

If @ does not work as expected in PHP 8, then this might be caused by a broken custom error handler. Please search for my_error_handler on https://www.php.net/manual/en/migration80.incompatible.php for an example of the necessary change.
 [2021-05-12 10:09 UTC] shop1 at mokraemer dot de
sorry. Thanks a lot - I didn't realize this change!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 30 07:01:28 2024 UTC