|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44246 closedir() accepts a file resource opened by fopen()
Submitted: 2008-02-25 16:55 UTC Modified: 2008-07-22 14:12 UTC
From: Assigned: felipe (profile)
Status: Closed Package: Directory function related
PHP Version: 5.2CVS-2008-02-25 (CVS) OS: Windows XP
Private report: No CVE-ID: None
 [2008-02-25 16:55 UTC]
closedir() will accept a file resource opened by fopen() as the $directory argument. In the documentation for closedir() it says the following: "The stream must have previously been opened by opendir()". It seems that the resource type is not being checked correctly. 
A directory opened with opendir() can also be passed to fclose() without an error message being generated.

Reproduce code:
var_dump($fp = fopen(__FILE__, 'r'));

$directory = dirname(__FILE__) . '/test';
var_dump($dh = opendir($directory));

Expected result:
resource(5) of type (stream)

Warning: closedir(): supplied argument is not a valid Directory resource in ...
resource(5) of type (stream)
resource(6) of type (stream)

Warning: fclose(): supplied argument is not a valid stream resource in ...
resource(6) of type (stream)

Actual result:
resource(5) of type (stream)
resource(5) of type (Unknown)
resource(6) of type (stream)
resource(6) of type (stream)


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-07-22 14:12 UTC]
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
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 26 07:01:30 2024 UTC