|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52383 readdir(false) behavior change
Submitted: 2010-07-20 21:15 UTC Modified: 2010-07-22 04:59 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: vc at artstyle dot net Assigned:
Status: Not a bug Package: Directory function related
PHP Version: 5.3.2 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: vc at artstyle dot net
New email:
PHP Version: OS:


 [2010-07-20 21:15 UTC] vc at artstyle dot net
Documentation at explains that

> This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE, such as 0 or "". Please read the section on Booleans for more information. Use the === operator for testing the return value of this function.

That was true for PHP 5.2.x and not so for 5.3.x:

# php -r 'var_dump(phpversion(), @readdir(false), @readdir(false)===false);'
string(8) "5.2.11-2"

# php -r 'var_dump(phpversion(), @readdir(false), @readdir(false)===false);'
string(7) "5.3.2-1"

This can make loop while (false !== ($file = readdir($handle))) {...} infinite if $handle was not checked beforehand.

Please consider to be more backward-compatible if this not cost much.


Test script:
php -r 'var_dump(@readdir(false), @readdir(false)===false);'             

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-07-22 04:59 UTC]
-Status: Open +Status: Bogus
 [2010-07-22 04:59 UTC]
This is to do with the new parameter parsing API that's used in PHP 5.3,
and is documented in the first bullet point of the migration guide's
list of incompatible changes [0] -- giving any built-in function an
invalid parameter (and readdir() certainly doesn't expect a boolean)
results in NULL being returned.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 07:01:29 2024 UTC