#44246 [Opn->Asn]: closedir() accepts a file resource opened by fopen()
| From: | felipe@php.net | Date: | Mon, 21 Jul 2008 14:36:04 +0000 |
| Subject: | #44246 [Opn->Asn]: closedir() accepts a file resource opened by fopen() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-127061@lists.php.net to get a copy of this message | ||
ID: 44246
Updated by: felipe@php.net
Reported By: jmessa@php.net
-Status: Open
+Status: Assigned
Bug Type: Directory function related
Operating System: Windows XP
PHP Version: 5.2CVS-2008-02-25 (CVS)
-Assigned To:
+Assigned To: felipe
Previous Comments:
------------------------------------------------------------------------
[2008-02-25 16:55:39] 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)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=44246&edit=1