sebastianbergmann/php-file-iterator — Issue #10: Endless loop in File_Iterator_Facade
Author: stronk7
Created: 2011-12-13 11:49:26+00:00
State: open

From wrongly created PEAR bug: https://pear.php.net/bugs/bug.php?id=19133

Description:
------------
Calling to File_Iterator_Facade->getFilesAsArray() with
$commonPath enabled, can lead to and endless loop if the
Iterator returns 0 matching files.

Test script:
---------------
100% reproducible against empty directory and/or 0 matching conditions.

Expected result:
----------------
File_Iterator_Facade->getFilesAsArray() to return empty
array().

Changing:

if ($commonPath) {

by

if ($files and $commonPath) {

prevents the getCommonPath() method to be called

Note:
-----

Note I've created one pull request against phpcpd to workaround this: https://pear.php.net/bugs/bug.php?id=19133
Fixing this will make the pull request unnecesary.

Ciao (and apologises by the confusion @ PEAR) :-)