#43529 [Ana->Csd]: readdir(), rewinddir() and closedir() don't always fail when passed 0 arguments
| From: | kalle@php.net | Date: | Fri, 08 Aug 2008 18:44:24 +0000 |
| Subject: | #43529 [Ana->Csd]: 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-1076@lists.php.net to get a copy of this message | ||
ID: 43529
Updated by: kalle@php.net
Reported By: robin_fernandes at uk dot ibm dot com
-Status: Analyzed
+Status: Closed
Bug Type: Documentation problem
Operating System: Windows
PHP Version: 5.3CVS-2007-12-07 (snap)
New Comment:
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.
Thank you for the report, and for helping us make our documentation
better.
Previous Comments:
------------------------------------------------------------------------
[2007-12-11 16:10:45] iliaa@php.net
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.
------------------------------------------------------------------------
[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