Home » File System » File_Find » Bug #67
maptree error: Problem with method call
Details
| Submitted | 2003-10-05 17:59 UTC |
|---|---|
| From | hetta at spamcop dot net |
| Assigned | techtonik |
| Status | Closed |
| Package | File_Find |
| PHP Version | 4.3.3 |
| OS | Suse81 linux 2.4.19-4GB #1 i686 |
| Roadmaps | (Not assigned) |
Comments
[2003-10-05 17:59 UTC] hetta at spamcop dot net
Description:
------------
ran a very simple maptree script, but got "problem with method call" on File_Find::_build($dir);
Reproduce code:
---------------
<?php
include_once 'File/Find.php';
list ($directories, $files) = File_Find::maptree('/www/htdocs');
?>
Expected result:
----------------
A list of files in the given directory, or a message saying "no files" or "no such directory".
Actual result:
--------------
Warning: Problem with method call - please report this bug in /usr/share/pear/File/Find.php on line 112
Warning: array_push(): First argument should be an array in /usr/share/pear/File/Find.php on line 113
lines 112-113 in File/Find.php:
File_Find::_build($dir);
array_push($this->directories, $dir);
----------
Changed that to a directory that actually exists - same result.
----------
Next I tried a directory with global read rights, and got:
Warning: Problem with method call - please report this bug in /usr/share/pear/File/Find.php on line 112
Warning: array_push(): First argument should be an array in /usr/share/pear/File/Find.php on line 258
... (lots of line 258) ...
Warning: array_push(): First argument should be an array in /usr/share/pear/File/Find.php on line 258
Warning: array_push(): First argument should be an array in /usr/share/pear/File/Find.php on line 113
[2003-10-05 18:07 UTC] tuupola at php dot net
You cannot call maptree() statically. Instead use something
like:
$f = new File_Find();
$file = $f->maptree('/tmp/');
[2003-10-05 18:15 UTC] hetta at spamcop dot net
Ah. Somebody needs to tell Sterling Hughes, of the "PHP Developer's Cookbook, Second Edition" then. ;)
http://safari.informit.com/0672323257/ch07lev1sec7
[2005-01-20 21:57 UTC] techtonik at tut dot by
Patch to allow maptree be called statically
--- Find_old.php 2005-01-10 18:33:00.000000000 +0200
+++ Find.php 2005-01-20 23:52:40.000000000 +0200
@@ -3,7 +3,7 @@
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
-// | Copyright (c) 1997-2003 The PHP Group |
+// | Copyright (c) 1997-2005 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
@@ -107,15 +107,22 @@
*/
function &maptree($directory)
{
- $this->_dirs = array($directory);
+ /* if called statically */
+ if (!isset($this) || !is_a($this, "File_Find")) {
+ $obj = &new File_Find();
+ return $obj->maptree($directory);
+ } else {
- while (count($this->_dirs)) {
- $dir = array_pop($this->_dirs);
- File_Find::_build($dir);
- array_push($this->directories, $dir);
- }
+ $this->_dirs = array($directory);
- return array($this->directories, $this->files);
+ while (count($this->_dirs)) {
+ $dir = array_pop($this->_dirs);
+ File_Find::_build($dir);
+ array_push($this->directories, $dir);
+ }
+
+ return array($this->directories, $this->files);
+ }
}
/**
@@ -199,7 +206,7 @@
{
/* if called statically */
- if (!isset($this) || !is_a($this, "File_Find")) {
+ if (!isset($this) || !is_a($this, "File_Find")) {
$obj = &new File_Find();
return $obj->search($pattern, $directory, $type, $fullpath);
} else {
[2005-01-20 22:16 UTC] techtonik at tut dot by
Well, here is a better link.
http://tech.zubr.com/wikipedia/File_Find-0.3.1-patched/
You better wget -r this page and compare with your working copy. I also modified all tests to run correctly on windows too.