ArrayMerge Errors with PHP5
jo1ene - February 24, 2006 - 18:09
| Project: | Filebrowser |
| Version: | 4.7.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | closed |
Jump to:
Description
Self explanatory. This modules generate a trio of related errors for each item it tries to display - and nothing is ever listed. It appears to be unusable with PHP5.

#1
I concur. Here is the error messages I recieve:
* warning: array_merge() [function.array-merge]: Argument #2 is not an array in C:\siteroot\drupal\modules\filebrowser\filebrowser.module on line 241.* warning: Invalid argument supplied for foreach() in C:\siteroot\drupal\modules\filebrowser\filebrowser.module on line 136.
* warning: Invalid argument supplied for foreach() in C:\siteroot\drupal\includes\theme.inc on line 738.
#2
line 245 is the contains the final arguments for this snippet of code:
$details[] = array_merge(array(
array('data' => $link, 'class' => 'filename', 'sv' => $file),
array('data' => $size, 'sv' => ($size ? $stat['size'] : 0)),
array('data' => format_interval($age), 'sv' => $age)
), $extrainfo);
#3
sorry i meant 241
#4
line 136 contains is apart of this code snippet:
foreach($files as $rnum => $filei) {foreach($filei as $cnum => $cell) {
if (is_array($cell)) {
unset($filei[$cnum]['sv']);
}
}
$files[$rnum] = $filei;
}
#5
this bug hasn't had much action, but in PHP 5 array_merge() takes only arrays for arguments. I think it is $extrainfo that causes this error, and a simple type cast "(array)" solves the error
#6
Change this:
$details[] = array_merge(array(
array('data' => $link, 'class' => 'filename', 'sv' => $file),
array('data' => $size, 'sv' => ($size ? $stat['size'] : 0)),
array('data' => format_interval($age), 'sv' => $age)
), $extrainfo);
to this:
$details[] = array_merge(array(
array('data' => $link, 'class' => 'filename', 'sv' => $file),
array('data' => $size, 'sv' => ($size ? $stat['size']: 0)),
array('data' => format_interval(time() - $stat['mtime']), 'sv' => (time() - $stat['mtime']))
), array($extrainfo));
for a quick fix.
#7
* dev-lang/php
Latest version available: 5.1.4
Latest version installed: 5.1.4
Size of downloaded files: 18,812 kB
Homepage: http://www.php.net/
Description: The PHP language runtime engine.
License: PHP-3
I made changes suggested above in #6 and still have this error listed below.
* warning: array_merge() [function.array-merge]: Argument #2 is not an array in /var/www/www.mysite.org/htdocs/drupal/modules/filebrowser/filebrowser.module on line 244.
* warning: array_merge() [function.array-merge]: Argument #2 is not an array in /var/www/www.mysite.org/htdocs/drupal/modules/filebrowser/filebrowser.module on line 244.
* warning: array_merge() [function.array-merge]: Argument #2 is not an array in /var/www/www.mysite.org/htdocs/drupal/modules/filebrowser/filebrowser.module on line 244.
* warning: array_merge() [function.array-merge]: Argument #2 is not an array in /var/www/www.mysite.org/htdocs/drupal/modules/filebrowser/filebrowser.module on line 244.
* warning: array_merge() [function.array-merge]: Argument #2 is not an array in /var/www/www.mysite.org/htdocs/drupal/modules/filebrowser/filebrowser.module on line 244.
* warning: Invalid argument supplied for foreach() in /var/www/www.mysite.org/htdocs/drupal/modules/filebrowser/filebrowser.module on line 137.
* warning: Invalid argument supplied for foreach() in /var/www/www.mysite.org/htdocs/drupal/modules/filebrowser/filebrowser.module on line 137.
* warning: Invalid argument supplied for foreach() in /var/www/www.mysite.org/htdocs/drupal/modules/filebrowser/filebrowser.module on line 137.
* warning: Invalid argument supplied for foreach() in /var/www/www.mysite.org/htdocs/drupal/modules/filebrowser/filebrowser.module on line 137.
* warning: Invalid argument supplied for foreach() in /var/www/www.mysite.org/htdocs/drupal/modules/filebrowser/filebrowser.module on line 137.
* warning: Invalid argument supplied for foreach() in /var/www/www.mysite.org/htdocs/drupal/includes/theme.inc on line 749.
* warning: Invalid argument supplied for foreach() in /var/www/www.mysite.org/htdocs/drupal/includes/theme.inc on line 749.
* warning: Invalid argument supplied for foreach() in /var/www/www.mysite.org/htdocs/drupal/includes/theme.inc on line 749.
* warning: Invalid argument supplied for foreach() in /var/www/www.mysite.org/htdocs/drupal/includes/theme.inc on line 749.
* warning: Invalid argument supplied for foreach() in /var/www/www.mysite.org/htdocs/drupal/includes/theme.inc on line 749.
Any ideas?
// The special one-up folder not in the root folderelseif ($file == ".." && !$inroot) {
$icon = filebrowser_get_icon(NULL, 'folder');
$link = "$icon $file";
$parts = explode("/", $subfolder);
array_pop($parts);
$up = t('up');
$link = l("$icon $file <$up>", filebrowser_proper_path(join("/", $parts)), array(), NULL, NULL, FALSE, TRUE);
$details[] = array_merge(
array(
array('data' => $link, 'class' => 'filename', 'sv' => $file),
array('data' => $size, 'sv' => ($size ? $stat['size']: 0)),
array('data' => format_interval(time() - $stat['mtime']), 'sv' => (time() - $stat['mtime']))
), array($extrainfo));
}
}
return $details;
}
#8
The fix in #6 seems to have worked for me.
#9
Drupal 4.7.2
PHP 5.1.2
MySQL 5.0.18-standard-log
I spoke to soon. The fix in #6 works for files that are not in subdirectories. With the fix in #6, files listed in the first level directory appear in the list properly with icon and download without any problem. With the fix in #6, clicking on a subdirectory listed in the filebrowser produced these errors:
[code]
Warning: array_merge() [function.array-merge]: Argument #2 is not an array in /drupal/modules/filebrowser/filebrowser.module on line 259
Warning: Invalid argument supplied for foreach() in /drupal/modules/filebrowser/filebrowser.module on line 137
Warning: Invalid argument supplied for foreach() in /drupal/includes/theme.inc on line 749
[/code]
Despite the errors, the subdirectory opened and filebrowser listed the files properly, and the files downloaded without problem.
Following the pattern in #6, I changed my line 259 in filebrowser.module from this:
[code]
$details[] = array_merge(array(
array('data' => $link, 'class' => 'filename', 'sv' => $file),
array('data' => '', 'sv' => 0),
array('data' => '', 'sv' => 0)
), $extrainfo);
[/code]
to this:
[code]
$details[] = array_merge(array(
array('data' => $link, 'class' => 'filename', 'sv' => $file),
array('data' => '', 'sv' => 0),
array('data' => '', 'sv' => 0)
), array($extrainfo));
[/code]
Seems to have resolved the errors associated with clicking on subdirectories.
#10
This should be easier to read.
Following the pattern in #6, I changed my line 259 in filebrowser.module from this:
$details[] = array_merge(array(array('data' => $link, 'class' => 'filename', 'sv' => $file),
array('data' => '', 'sv' => 0),
array('data' => '', 'sv' => 0)
), $extrainfo);
to this:
$details[] = array_merge(array(array('data' => $link, 'class' => 'filename', 'sv' => $file),
array('data' => '', 'sv' => 0),
array('data' => '', 'sv' => 0)
), array($extrainfo));
Seems to have resolved the errors associated with clicking on subdirectories.
#11
I have just committed some fixes into the HEAD (cvs) and 4.7 versions of filebrowser to support PHP 5 better. Please try with the latest module. Unfortunately I don't have a Drupal on PHP 5 at hand right now. The diffs for the HEAD and 4.7 versions are the same and quite simple:
http://cvs.drupal.org/viewcvs/drupal/contributions/modules/filebrowser/f...
http://cvs.drupal.org/viewcvs/drupal/contributions/modules/filebrowser/f...
Do not apply the fix suggested here in #6, it will break other things.
#12
Tested with later filebrowser code and PHP 5 and found no array_merge() errors.