php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64989 more accurate return value for readdir()
Submitted: 2013-06-07 15:08 UTC Modified: 2013-06-07 15:56 UTC
From: vosa at binaryparadise dot com Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: Irrelevant OS: linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: vosa at binaryparadise dot com
New email:
PHP Version: OS:

 

 [2013-06-07 15:08 UTC] vosa at binaryparadise dot com
Description:
------------
---
From manual page: http://www.php.net/function.readdir#refsect1-function.readdir-examples
---

From documentation: "Returns the entry name on success or FALSE on failure." Function returns NULL instead of FALSE in case of bad dir_handler. I think it should be mentioned in documentation at least.
If dir_handler is not exactly resource, then i.e.: "while(FALSE === readdir('definitely_not_handler'));" can end very badly.

Test script:
---------------
var_dump(readdir('definitely_not_handler'));

Expected result:
----------------
FALSE

Actual result:
--------------
NULL

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-06-07 15:14 UTC] vosa at binaryparadise dot com
Sorry for bad example in original message. Correct one:

while(FALSE !== readdir('definitely_not_handler'));
 [2013-06-07 15:56 UTC] laruence@php.net
-Status: Open +Status: Not a bug
 [2013-06-07 15:56 UTC] laruence@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

return null on argument passing failed is expected and right behavior

if you enable E_WARNING report, you will find a warning is threw, like:
"PHP Warning:  readdir() expects parameter 1 to be resource, string given"
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri May 02 19:01:29 2025 UTC