Doc #63205 [Nab]: readdir() failure returns NULL instead of false

From: Date: Fri, 16 Nov 2012 05:21:23 +0000
Subject: Doc #63205 [Nab]: readdir() failure returns NULL instead of false
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-9161@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 User updated by: ai0867 at gmail dot com Reported by: ai0867 at gmail dot com Summary: readdir() failure returns NULL instead of false 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: The documentation still says nothing about returning NULL, while telling the programmer to differentiate between FALSE and all other values. I did file this bug as a documentation problem. Previous Comments: ------------------------------------------------------------------------ [2012-11-15 10:11:23] krakjoe@php.net 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. ------------------------------------------------------------------------ [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

« previous php.doc.bugs (#9161) next »