Welcome to Egypt Forums Mark forums read | Egypt Main Page
Egypt Forums
Arabic Movies



Articles Thread, [Fix How to] PHP 5 and array_merge errors in vBulletin; [Fix How to] PHP 5 and array_merge errors If you've upgraded to php 5 on your server you may have ...

Short Link: http://forum.egypt.com/enforum/showthread.php?t=6066


Reply
LinkBack Thread Tools Display Modes
[Fix How to] PHP 5 and array_merge errors
 
 
The God Father
Developer's Avatar

Reply With Quote
 
Join Date: Jul 2008
Location: NDC
Posts: 5,425
06-11-2008, 07:44 PM
 
[Fix How to] PHP 5 and array_merge errors

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:
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:
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.
__________________
I Love Walking In The Rain Cuz Nobody Know I'm Crying !!
 
 
 
 
Junior Member

Reply With Quote
 
Join Date: Apr 2009
Location: USA
Posts: 1
27-04-2009, 03:08 AM
 
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);
__________________
car zone
 
 
 
Reply

Articles Thread, [Fix How to] PHP 5 and array_merge errors in vBulletin; [Fix How to] PHP 5 and array_merge errors If you've upgraded to php 5 on your server you may have ...

Short Link: http://forum.egypt.com/enforum/showthread.php?t=6066


Bookmarks

Tags
arraymerge, errors, fix, php


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump