php.net |  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
Votes:1
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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: vc at artstyle dot net
New email:
PHP Version: OS:

 

 [2010-07-20 21:15 UTC] vc at artstyle dot net
Description:
------------
Documentation at http://php.net/readdir 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"
bool(false)
bool(true)

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

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.

Thanks!


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


Expected result:
----------------
bool(false)
bool(true)


Actual result:
--------------
NULL
bool(false)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-07-22 04:59 UTC] aharvey@php.net
-Status: Open +Status: Bogus
 [2010-07-22 04:59 UTC] aharvey@php.net
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.

[0] http://php.net/manual/en/migration53.incompatible.php
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 11:01:30 2024 UTC