PHP5(Win '03): warning: array_merge() [function.array-merge]: Argument #2 is not an array in C:\<mod directory>\pacs\pacs.module

gcopenhaver - October 20, 2006 - 15:51
Project:Tree Access Module (pacs)
Version:4.7.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed
Description

I'm using PHP5 (on Windows Server 2003 using IIS 6.0) I was getting this error while viewing the tree tab on nodes. Clicking various other nodes and roles would cause multiple of these errors at the same time.
Here's the error:

warning: array_merge() [function.array-merge]: Argument #2 is not an array in C:\\modules\pacs\pacs.module on line 60.

I dug through the code in the module and had it print

I found out that in PHP5 the array_merge() function now only accepts of type array.

"The behavior of array_merge() was modified in PHP 5. Unlike PHP 4, array_merge() now only accepts parameters of type array. However, you can use typecasting to merge other types." - http://us2.php.net/array_merge

So I added the (array) typecast to the second argument of the array_merge($nde,$grs) function. The line changed from:
if (isset($grs)) $nde = array_merge($nde,$grs);
to:
if (isset($grs)) $nde = array_merge($nde,(array)$grs);

Now the errors are gone. I'm not sure how this may affect the module overall and needs to be reviewed. As far as I can tell, everything is working fine after that change. I don't think it should affect anything in PHP4, but I don't have drupal setup on PHP4 currently, so I can't test it.
I attached a patch, though it's an extremely minor change.

AttachmentSize
pacs.module.patch.txt513 bytes

#1

peterone - April 11, 2007 - 14:14
Status:needs review» fixed

Thank you very much, gcopenhaver.

I just fixed it, but I opted to change the isset() function to empty():
if (!empty($grs)) $nde = array_merge($nde,$grs);

#2

Anonymous - April 25, 2007 - 14:16
Status:fixed» closed
 
 

Drupal is a registered trademark of Dries Buytaert.