#43529 [Opn->Ana]: readdir(), rewinddir() and closedir() don't always fail when passed 0 arguments
| From: | iliaa@php.net | Date: | Tue, 11 Dec 2007 16:10:46 +0000 |
| Subject: | #43529 [Opn->Ana]: readdir(), rewinddir() and closedir() don't always fail when passed 0 arguments | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-342@lists.php.net to get a copy of this message | ||
ID: 43529
Updated by: iliaa@php.net
Reported By: robin_fernandes at uk dot ibm dot com
-Status: Open
+Status: Analyzed
-Bug Type: Directory function related
+Bug Type: Documentation problem
Operating System: Windows
PHP Version: 5.3CVS-2007-12-07 (snap)
New Comment:
The docs for these 3 functions (readdir(), rewinddir() and closedir())
are wrong. The code allows the parameter to be empty, in which case the
currently opendir from the last opendir() call is used.
Previous Comments:
------------------------------------------------------------------------
[2007-12-07 15:38:22] robin_fernandes at uk dot ibm dot com
Description:
------------
According to the docs, readdir(), rewinddir() and closedir() should
take at least one argument: the directory handle.
However, these methods are also aliases for the Directory class methods
Directory::read(), Directory::rewind() and Directory::close(). Instances
of the Directory class hold the directory handle in $this->handle.
Therefore, if no argument is passed, the implementation of these
methods is such that $this->handle is used as the directory handle.
However, no check is made to ensure $this is an instance of Directory.
Consequently, calling readdir() etc.. with no arguments from a context
where $this->handle just happens to exists will result in unexpected
behaviour instead of an error message.
Reproduce code:
---------------
<?php
Class C {
public $handle;
function test() {
// Expecting failure.
var_dump(readdir());
var_dump(rewinddir());
var_dump(closedir());
}
}
$c = new C;
$c->handle = opendir(getcwd());
$c->test();
?>
Expected result:
----------------
Warning: readdir(): no Directory resource supplied in %s on line 6
bool(false)
Warning: rewinddir(): no Directory resource supplied in %s on line 7
bool(false)
Warning: closedir(): no Directory resource supplied in %s on line 8
bool(false)
Actual result:
--------------
string(1) "."
NULL
NULL
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=43529&edit=1