Doc #75136 [Opn->Nab]: readdir is returning null.

From: Date: Wed, 30 Aug 2017 13:40:32 +0000
Subject: Doc #75136 [Opn->Nab]: readdir is returning null.
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-14937@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 Updated by: salathe@php.net Reported by: dmitriy dot vinograd at gmail dot com Summary: readdir is returning null. -Status: Open +Status: Not a bug Type: Documentation Problem -Package: Directory function related +Package: Documentation problem Operating System: Ubuntu 16.04.3 LTS PHP Version: 7.0.22 Block user comment: N Private report: N New Comment: Closing as not a bug for the readdir() page. Returning NULL is a convention widely used throughout PHP and is not something we document for every individual function. " Note: If the parameters given to a function are not what it expects, such as passing an array where a string is expected, the return value of the function is undefined. In this case it will likely return NULL but this is just a convention, and cannot be relied upon." -- http://php.net/manual/en/functions.internal.php Previous Comments: ------------------------------------------------------------------------ [2017-08-30 13:22:20] spam2 at rhsoft dot net what makes YOU think NULL is the correct return in case of a invalid param when the doc says it returns boolean flase when not sucessful anyways, that's why i ported a 250000 LOC codebase in the last year to declare(strict_types=1); which would lead to a exception in the case below ------------------------------------------------------------------------ [2017-08-30 13:20:11] dmitriy dot vinograd at gmail dot com // The documentation actually alerts you that this is a possible return value. Quoting: Yes, you are absolutely right. Despite the fact, I still don't see any reasons why the function is returning null in this case. Also, I would like to add that mentioned code wasn't implemented by me and I suppose an author was encouraged by the example from the documentation. Also, I personally believe that this is a pretty hard to predict consequences from this warning message. ------------------------------------------------------------------------ [2017-08-30 13:08:51] dmitriy dot vinograd at gmail dot com //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))) ------------------------------------------------------------------------ [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? ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=75136 -- Edit this bug report at https://bugs.php.net/bug.php?id=75136&edit=1

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