|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-12-11 16:10 UTC] iliaa@php.net
[2008-08-08 18:44 UTC] kalle@php.net
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Dec 10 03:00:01 2025 UTC |
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