From:             robin_fernandes at uk dot ibm dot com
Operating system: Windows
PHP version:      5.3CVS-2007-12-07 (snap)
PHP Bug Type:     Directory function related
Bug description:  readdir(), rewinddir() and closedir() don't always fail when 
passed 0 arguments

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 bug report at http://bugs.php.net/?id=43529&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=43529&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=43529&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): 
http://bugs.php.net/fix.php?id=43529&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=43529&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=43529&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=43529&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=43529&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=43529&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=43529&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=43529&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=43529&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=43529&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=43529&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=43529&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=43529&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=43529&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=43529&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=43529&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=43529&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=43529&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=43529&r=mysqlcfg

Reply via email to