PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » File System » File_Find » Bug #4669

Repeated calls to search or maptree return multiple copies of results

Details

Submitted2005-06-23 18:24 UTC
Fromepgremill3 at yahoo dot com
Assignedtuupola
StatusClosed
PackageFile_Find
PHP Version5.0.3
OSWindows XP Pro
Roadmaps(Not assigned)

Comments

[2005-06-23 18:24 UTC] epgremill3 at yahoo dot com

Description:
------------
Repeated calls to File_Find::search with the same parameters yields multiple copies of the matching files in the results. I'm using File_Find 0.2.0.

I believe this is happening because maptree does not clear the $directories and $files member variables of the File_Find class. I can correct for this problem by creating a new instance of File_Find before each call to maptree or search.

I alternatively corrected for the problem by modifying the maptree and _build functions to use function-scope variables instead of the class member variables. This gave the added benefit of allowing static calls to maptree and search. If you would like to see my code, I would happily email it to you.

Reproduce code:
---------------
require_once("File/Find.php");
$pattern = "/User.*\.php/";
$dirpath = $_SERVER["DOCUMENT_ROOT"] . "/com/exceptionals";
$dirpath = str_replace("/", "\\", $dirpath);
$pattern_type = "perl";
$f = new File_Find();
$res = $f->search($pattern, $dirpath, $pattern_type);
$res = $f->search($pattern, $dirpath, $pattern_type);
echo("<p>\n");
print_r($res);
echo("</p>\n");

Expected result:
----------------
Array ( [0] => C:\Documents and Settings\Ernie Gremillion\My Documents\Exceptionals\Website\com\exceptionals\data_access\UserData.class.php [1] => C:\Documents and Settings\Ernie Gremillion\My Documents\Exceptionals\Website\com\exceptionals\application\User.class.php )

Actual result:
--------------
Array ( [0] => C:\Documents and Settings\Ernie Gremillion\My Documents\Exceptionals\Website\com\exceptionals\data_access\UserData.class.php [1] => C:\Documents and Settings\Ernie Gremillion\My Documents\Exceptionals\Website\com\exceptionals\application\User.class.php [2] => C:\Documents and Settings\Ernie Gremillion\My Documents\Exceptionals\Website\com\exceptionals\data_access\UserData.class.php [3] => C:\Documents and Settings\Ernie Gremillion\My Documents\Exceptionals\Website\com\exceptionals\application\User.class.php )