Back to vBulletin 3 Articles

[Fix How to] PHP 5 and array_merge errors
by Brad 30 Aug 2006

If you've upgraded to php 5 on your server you may have seen some of your plug-in's and add-ons throwing errors like this:

Warning: array_merge() [function.array-merge]: Argument #1 is not an array in /index.php(486) : eval()'d code on line 79
This is a common error, we updated our server to php 5 yesterday and I've already seen the error come up twice for two plug-ins on our forum. Another site on the server is running vBadvanced, its news module also threw the same error.

The reason this came up is due to a change in the way array_merge works in php 5. Basically it will no longer accept anything but an array without throwing an error. Thankfully it's just an 'incorrect usage' error and our code still works as it should, it just throws an error now.

The correct way to fix this is not using array merge with anything but arrays. However we already have a lot of code lying around doing things like this:

PHP Code:
$var 'option1';
$array = array('option2''option3''option4');

$array array_merge($var$array); 
Obviously most of us aren't looking to re-write some of this code just so it works under php 5. Thankfully there is a very simple fix for this that won't force us to change much of anything.

Just change your code so it looks like this:

PHP Code:
$var 'option1';
$array = array('option2''option3''option4');

$array array_merge((array)$var$array); 
Notice the (array) next to $var now? That is the only change needed. Your code should now work under php 5 and no longer throw array_merge errors.

vblts.ru supports vBulletin®, 2022-2024