Doc #63205 [Com]: readdir() failure returns NULL instead of false
| From: | inscriptions at starbender dot com | Date: | Thu, 25 Oct 2012 13:22:16 +0000 |
| Subject: | Doc #63205 [Com]: readdir() failure returns NULL instead of false | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-9010@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
Comment by: inscriptions at starbender dot com
Reported by: ai0867 at gmail dot com
Summary: readdir() failure returns NULL instead of false
Status: Open
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:
I also have the same problem with PHP-5.3.17 on SuSE
Previous Comments:
------------------------------------------------------------------------
[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