php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44295 DirectoryIterator::__construct() exception + set_error_handler broken
Submitted: 2008-02-29 20:52 UTC Modified: 2008-03-09 12:09 UTC
From: web-php-bugs at sklar dot com Assigned: colder (profile)
Status: Closed Package: SPL related
PHP Version: 5.2.5 OS: OS X 10.4
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: web-php-bugs at sklar dot com
New email:
PHP Version: OS:

 

 [2008-02-29 20:52 UTC] web-php-bugs at sklar dot com
Description:
------------
When set_error_handler() has been used to set a custom error handler, the RuntimeException thrown by DirectoryIterator::__construct() is not handled properly -- the user error handler runs and then code continues after the constructor instead of the exception being thrown.

This is specific to DirectoryIterator, if you replace "$iter = new DirectoryIterator($dir)" with just "throw new Exception('monkey');" in the reproduce code below, the catch block executes OK.


Reproduce code:
---------------
<?php

error_reporting(E_ALL | E_STRICT);
ini_set('display_errors',true);
$dir = '/this/path/does/not/exist';

set_error_handler('my_error_handler');
function my_error_handler() { print "in error handler\n"; }


try {
    print "before\n";
    $iter = new DirectoryIterator($dir);
    print get_class($iter) . "\n";
    print "after\n";
} catch (Exception $e) {
    print "in catch\n";
}

Expected result:
----------------
before
in catch


Actual result:
--------------
before
in error handler
DirectoryIterator
after


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-03-09 12:09 UTC] colder@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 [2012-05-10 15:36 UTC] ab@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src.git;a=commit;h=266578f58483a08d7af51714636564df36a926d0
Log: Fix bug #61992 ext\standard\tests\general_functions\bug44295.phpt fails
 [2014-10-07 23:26 UTC] stas@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=266578f58483a08d7af51714636564df36a926d0
Log: Fix bug #61992 ext\standard\tests\general_functions\bug44295.phpt fails
 [2014-10-07 23:37 UTC] stas@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=266578f58483a08d7af51714636564df36a926d0
Log: Fix bug #61992 ext\standard\tests\general_functions\bug44295.phpt fails
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 04:01:36 2025 UTC