Doc #75136 [Fbk->Opn]: readdir is returning null.
| From: | dmitriy dot vinograd at gmail dot com | Date: | Wed, 30 Aug 2017 13:08:51 +0000 |
| Subject: | Doc #75136 [Fbk->Opn]: readdir is returning null. | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-14934@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75136&edit=1
ID: 75136
User updated by: dmitriy dot vinograd at gmail dot com
Reported by: dmitriy dot vinograd at gmail dot com
Summary: readdir is returning null.
-Status: Feedback
+Status: Open
Type: Documentation Problem
Package: Directory function related
Operating System: Ubuntu 16.04.3 LTS
PHP Version: 7.0.22
Block user comment: N
Private report: N
New Comment:
//What makes you think false is a valid argument for the function?
Nothing we even have a check in our code to pretend it, but when you have a lot of processes there
is still a chance that it happens in between. Which may occur with our site yesterday,
if ($dir = opendir($filePath) && is_numeric($noOfDays) > 0)
{
while (false !== ($logFile = readdir($dir)))
Previous Comments:
------------------------------------------------------------------------
[2017-08-30 13:01:37] mail at pmmaga dot net
The documentation actually alerts you that this is a possible return value. Quoting:
Warning
This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to
FALSE. Please read the section on Booleans for more information. Use the === operator for testing
the return value of this function.
------------------------------------------------------------------------
[2017-08-30 12:57:50] salathe@php.net
What makes you think false is a valid argument for the function?
------------------------------------------------------------------------
[2017-08-30 12:51:10] dmitriy dot vinograd at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.readdir
---
readdir(false) is returning a null, despite the fact documentation says it must be a string or false
Which may put the example from the documentation in an infinitive loop, and in case if a server is
saving warning messages into a log it will fill the server disk that in turn will put the server
offline.
Test script:
---------------
var_dump(readdir(false));
//Will return
// Warning: readdir() expects parameter 1 to be resource, boolean given in /..../test.php on line 11
// /..../test.php:11:null
while (false !== ($logFile = readdir(false)))
{
var_dump($logFile);
}
// Will put your process an infinitive loop
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75136&edit=1