Doc #63205 [Opn->Nab]: readdir() failure returns NULL instead of false
| From: | krakjoe@php.net | Date: | Thu, 15 Nov 2012 10:11:23 +0000 |
| Subject: | Doc #63205 [Opn->Nab]: readdir() failure returns NULL instead of false | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-9142@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=63205&edit=1
ID: 63205
Updated by: krakjoe@php.net
Reported by: ai0867 at gmail dot com
Summary: readdir() failure returns NULL instead of false
-Status: Open
+Status: Not a bug
Type: Documentation Problem
Package: Directory function related
Operating System: Debian Squeeze
PHP Version: 5.3.17
Block user comment: N
Private report: N
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
Conventions established; it is the responsibility of the programmer to ascertain
that the parameters they pass to a function or method are valid. The programmer
should handle the return of the call to opendir without the assumption that the
call succeeded.
Previous Comments:
------------------------------------------------------------------------
[2012-10-25 13:22:16] inscriptions at starbender dot com
I also have the same problem with PHP-5.3.17 on SuSE
------------------------------------------------------------------------
[2012-10-19 12:02:10] joko at mms-dresden dot de
The error also occurs on RHEL 5.8 using PHP versions 5.3.15, 5.3.16 and 5.3.17. I
was not able to test other versions.
Since max_execution_time does not apply to readdir, the following code (present
in Typo3) will trigger an endless loop which
continues to run even after the user has aborted the HTTP request.
while (($file = readdir($handle)) !== FALSE) {
...
}
------------------------------------------------------------------------
[2012-10-03 09:30:30] ai0867 at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.readdir#refsect1-function.readdir-
returnvalues
---
readdir() should return the boolean value false on failure. When calling it on a
failed opendir() result (false), it returns NULL instead.
http://www.php.net/manual/en/functions.internal.php
This indicates that this is intentional, but the readdir() documentation says
nothing about this.
Test script:
---------------
$dir = opendir("/tmp/this-dir-does-not-exist");
$item = readdir($dir);
var_dump($item); // Should be false. Returns NULL on my machine
Expected result:
----------------
false
Actual result:
--------------
PHP Warning: opendir(/tmp/this-dir-does-not-exist): failed to open dir: No such
file or directory in /home/ai/test.php on line 2
PHP Warning: readdir() expects parameter 1 to be resource, boolean given in
test.php on line 3
NULL
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=63205&edit=1