php.net |  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: jmessa@php.net 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] jmessa@php.net
Description:
------------
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:
---------------
<?php
var_dump($fp = fopen(__FILE__, 'r'));
closedir($fp);
var_dump($fp);

$directory = dirname(__FILE__) . '/test';
mkdir($directory);
var_dump($dh = opendir($directory));
var_dump(fclose($dh));
var_dump($dh);
?>

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 ...
bool(false)
resource(6) of type (stream)

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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-07-22 14:12 UTC] felipe@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.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC