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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: shop1 at mokraemer dot de
New email:
PHP Version: OS:

 

 [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 03:01:31 2024 UTC