php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65326 set_exception_handler and requiring non-existent file
Submitted: 2013-07-24 14:55 UTC Modified: 2013-07-26 00:23 UTC
From: yuri dot kanivetsky at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.4.17 OS: linux, windows
Private report: No CVE-ID: None
 [2013-07-24 14:55 UTC] yuri dot kanivetsky at gmail dot com
Description:
------------
My code converts errors to exceptions, but it turned out that when faced with 
"Failed opening required 'whatever'" error, exception handler doesn't get called. 
More precisely, it doesn't work for require, but works for include.

I tested it on debian 6.0.6 (php-5.4.15), on arch linux (php-5.4.17) and on 
windows 7 (php-5.4.17).

Test script:
---------------
#!/usr/bin/env php
<?php

set_error_handler(function() {
    echo "error\n";
    throw new Exception;
});
set_exception_handler(function() {
    echo "exception\n";
});
require 'asdf';


Expected result:
----------------
error
exception


Actual result:
--------------
error
PHP Warning:  Uncaught exception 'Exception' in /home/yuri/1.php:6
Stack trace:
#0 /home/yuri/1.php(11): {closure}(2, 'require(asdf): ...', '/home/yuri/1.ph...', 
11, Array)
#1 /home/yuri/1.php(11): require()
#2 {main}
  thrown in /home/yuri/1.php on line 6
PHP Fatal error:  main(): Failed opening required 'asdf' 
(include_path='.:/usr/share/php:/usr/share/pear') in /home/yuri/1.php on line 11

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-07-26 00:23 UTC] yohgaki@php.net
-Status: Open +Status: Not a bug
 [2013-07-26 00:23 UTC] yohgaki@php.net
Since you are requiring non existent file with "require", it stops execution due 
to E_ERROR.

Try it with "include", it should work.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat May 03 13:01:30 2025 UTC