php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74366 Throwable not catching include and require
Submitted: 2017-04-03 18:53 UTC Modified: 2017-04-04 07:13 UTC
From: tugrultopuz at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 7.0.17 OS: Debian 8.5
Private report: No CVE-ID: None
 [2017-04-03 18:53 UTC] tugrultopuz at gmail dot com
Description:
------------
Throwable not catching the error by include and require statements for non existent files.

Test script:
---------------
try {
    include 'non-existent-file.php';
} catch (\Throwable $ex) {
    echo 'include error';
}

try {
    include_once 'non-existent-file.php';
} catch (\Throwable $ex) {
    echo 'include_once error';
}

try {
    require 'non-existent-file.php';
} catch (\Throwable $ex) {
    echo 'require error';
}

try {
    require_once 'non-existent-file.php';
} catch (\Throwable $ex) {
    echo 'require once error';
}

Expected result:
----------------
include error
include_once error
require error
require_once error

Actual result:
--------------
no output and write errors to error log

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-04-03 19:00 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2017-04-03 19:00 UTC] requinix@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

include/require raise warnings and errors, not exceptions. If you can't see the messages then you need to adjust your error reporting settings.
 [2017-04-03 20:21 UTC] tugrultopuz at gmail dot com
This should possible in PHP 7 by the documentation

http://php.net/manual/en/language.errors.php7.php
 [2017-04-04 07:12 UTC] a at b dot c dot de
PHP 7 changes how *most* errors are reported by PHP. Instead of reporting errors through the traditional error reporting mechanism used by PHP 5, *most* errors are now reported by throwing Error exceptions.
 [2017-04-04 07:13 UTC] requinix@php.net
Making require/require_once throw \Error is part of request #72089.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 05:01:33 2024 UTC