Edit report at http://bugs.php.net/bug.php?id=52383&edit=1

 ID:               52383
 Updated by:       ahar...@php.net
 Reported by:      vc at artstyle dot net
 Summary:          readdir(false) behavior change
-Status:           Open
+Status:           Bogus
 Type:             Bug
 Package:          Directory function related
 Operating System: Linux
 PHP Version:      5.3.2

 New Comment:

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


Previous Comments:
------------------------------------------------------------------------
[2010-07-20 21:15:24] 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)




------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=52383&edit=1

Reply via email to