Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 3 Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
[Fix How to] PHP 5 and array_merge errors
Brad
Join Date: Nov 2001
Posts: 4,765

 

Show Printable Version Email this Page Subscription
Brad Brad is offline 08-29-2006, 10:00 PM

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:

Quote:
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.
Reply With Quote
  #2  
Old 03-16-2007, 04:13 AM
Abe1's Avatar
Abe1 Abe1 is offline
 
Join Date: Feb 2004
Location: I LOVE New York!
Posts: 2,886
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

If you do just this change? Will this script work for php4?
Reply With Quote
  #3  
Old 03-16-2007, 05:07 AM
Guest190829
Guest
 
Posts: n/a
Default

Yes, the fix is just type casting the value into the array, however, if you know that you are only adding other types of data on to the array, just use array_push() or $var[] = 'option1';

PHP Code:

$array 
= array('option1''option2''option3');

$array[] = 'option4';

// or: (although $array[] = 'option4' is quicker)

array_push($array'option4'); 
Reply With Quote
  #4  
Old 05-19-2007, 08:20 AM
deathemperor's Avatar
deathemperor deathemperor is offline
 
Join Date: Jul 2003
Location: HOL
Posts: 1,270
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

this small fix helps
Reply With Quote
  #5  
Old 01-11-2008, 08:44 PM
mystic10 mystic10 is offline
 
Join Date: Sep 2007
Posts: 298
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

i have the same problem but with functions.php

this is my error: array_merge() [function.array-merge]: Argument #1 is not an array in /includes/functions.php(1259) : eval()'d code on line 5

i tried to look for the above things in fuctions.php but was unscusseful...maybe u can help me as well
Reply With Quote
  #6  
Old 01-11-2008, 10:43 PM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by mystic10 View Post
Argument #1 is not an array in /includes/functions.php(1259) : eval()'d code on line 5

i tried to look for the above things in fuctions.php but was unscusseful...maybe u can help me as well
eval()'d code normally refers to when a template/plugin is executed. Find the plugin(s) that use the hook in functions.php on line 1259, it will be on the 5th line of the Plugin PHP Code.
Reply With Quote
  #7  
Old 02-18-2008, 05:25 AM
seangworld's Avatar
seangworld seangworld is offline
 
Join Date: Sep 2002
Location: Chesapeake, VA
Posts: 272
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

im fn lost. this sh.it doesnt help when you cant find the stupid code at all. then what the hell is the option 1, 2, 3, 4???
Reply With Quote
  #8  
Old 02-28-2008, 05:38 PM
allaf2 allaf2 is offline
 
Join Date: Feb 2007
Posts: 4
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I have the same problem as mystic10 i get the same error and the error is this (array_merge() [function.array-merge]: Argument #1 is not an array in /includes/functions.php(1259) : eval()'d code on line 5) and i dont know what i should do or what to do can you plz help me
Reply With Quote
  #9  
Old 02-29-2008, 06:20 PM
Brad Brad is offline
 
Join Date: Nov 2001
Posts: 4,765
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by seangworld View Post
im fn lost. this sh.it doesnt help when you cant find the stupid code at all. then what the hell is the option 1, 2, 3, 4???
If you're having problems finding the code throwing the error you probably shouldn't be poking around in the files in the first place. At the very least you shouldn't be acting all high and mighty and calling my thread "shit".

Try asking nicely for help, and add a please, and include full error messages and I'll try to help you.

Yes I'm an ass hole, but only when provoked. I'm pretty friendly if you come at me with respect.

Quote:
Originally Posted by allaf2
I have the same problem as mystic10 i get the same error and the error is this (array_merge() [function.array-merge]: Argument #1 is not an array in /includes/functions.php(1259) : eval()'d code on line 5) and i dont know what i should do or what to do can you plz help me
You have an error in one of your plug-ins at the hook located at line 1259 of /includes/functions.php.

Open functions.php and locate that line, on it you'll find a line of code similar to this one:

PHP Code:
($hook vBulletinHook::fetch_hook('hook_name')) ? eval($hook) : false
In the above example "hook_name" is the name of the hook location we need to find.

Once you have the name of the hook location go into the plug-in manager in the admincp and find all plug-ins using that location. The code throwing the error is located in one of them.
Reply With Quote
  #10  
Old 03-17-2008, 04:35 AM
dancue dancue is offline
 
Join Date: Feb 2008
Posts: 569
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This is my error:
Warning: array_merge() [function.array-merge]: Argument #2 is not an array in /index.php(537) : eval()'d code on line 119

I've found the plug-in causing the error. I opened it saw an array and did as instructed above, but still received the same error.

Can anyone help me with this please?

Here is the code within the plug-in:
Code:
if($vbulletin->options['siteteam_active'] == 1) { 
                    $userid = $vbulletin->userinfo['userid'];  
                    $languageid = $vbulletin->userinfo['languageid']; 
                    $user = $vbulletin->db->query_first_slave(" 
                        SELECT language.phrasegroup_siteteam AS phrasegroup_siteteam 
                        FROM ".TABLE_PREFIX."user AS user 
                        LEFT JOIN ".TABLE_PREFIX."language AS language  
                            ON (language.languageid = " . (!empty($languageid) ? $languageid : "IF(user.languageid = 0, " . intval($vbulletin->options['languageid']) . ", user.languageid)") . ") 
                        WHERE user.userid = $userid 
                    "); 
                    $tmp = unserialize($user["phrasegroup_siteteam"]); 
                    $vbphrase = array_merge($vbphrase, $tmp); 
                 
                require_once('includes/functions_user.php'); 
                require_once('includes/functions_bigthree.php'); 

                $limit = $vbulletin->options['siteteam_count']; 
                $teamarray = $vbulletin->db->query_read("  
                  SELECT * 
                  FROM ".TABLE_PREFIX."user 
                        JOIN ".TABLE_PREFIX."usergroup AS ugroup 
                            ON ugroup.usergroupid=".TABLE_PREFIX."user.usergroupid 
                        LEFT JOIN ".TABLE_PREFIX."usergroup  
                            ON (FIND_IN_SET(".TABLE_PREFIX."usergroup.usergroupid, ".TABLE_PREFIX."user.membergroupids)) 
                        WHERE ugroup.siteteam=1 OR ".TABLE_PREFIX."usergroup.siteteam=1 
                        GROUP BY ".TABLE_PREFIX."user.userid 
                  ORDER BY RAND() 
                  LIMIT $limit 
                ");  
                while ($team = $vbulletin->db->fetch_array($teamarray)){ 
                  if($vbulletin->options['siteteam_type']== 1) { 
              $avatarurl = fetch_avatar_url($team['userid']); 
                    if (!$avatarurl) { 
                        $teamavatar = 'images/misc/noavatar.gif'; 
                      } else     { 
                        $teamavatar = $vbulletin->options['bburl'] . '/' . $avatarurl[0]; 
                      } 
                    } else { 
                            $teamavatar = ''; 
                            $teamuserinfo = verify_id('user', $team['userid'], 1, 1, 47); 
                            $showprofilepic = ($vbulletin->options['profilepicenabled'] AND  
                                                                    $teamuserinfo['profilepic'] AND  
                                                                     ($permissions['genericpermissions'] &  
                                                                      $vbulletin->bf_ugp_genericpermissions['canseeprofilepic'] OR  
                                                                      $vbulletin->userinfo['userid'] == $teamuserinfo['userid'])) ? true : false; 
                            if($vbulletin->options['usefileavatar'])    { 
                                $teamavatar = $vbulletin->options['profilepicurl'] . '/profilepic' . $teamuserinfo['userid'] . '_' . $teamuserinfo['profilepicrevision'] . '.gif'; 
                            }    else { 
                                $teamavatar = 'image.php?' . $vbulletin->session->vars['sessionurl'] . 'u=' . $teamuserinfo['userid'] . "&dateline=$teamuserinfo[profilepicdateline]&type=profile"; 
                            } 

                  if(empty($teamavatar) || !$showprofilepic) { 
                        $avatarurl = fetch_avatar_url($team['userid']); 
                      if(!$avatarurl) { 
                          $teamavatar = 'images/misc/noavatar.gif'; 
                        } else { 
                          $teamavatar = $vbulletin->options['bburl'] . '/' . $avatarurl[0]; 
                        } 
                      }  
                    } 
                        $userinfo = verify_id('user', $team['userid'], 1, 1); 
                      $userinfo['lastactivitydate'] = vbdate($vbulletin->options['dateformat'], $userinfo['lastactivity'], true); 
                    $userinfo['lastactivitytime'] = vbdate($vbulletin->options['timeformat'], $userinfo['lastactivity']); 
                      $useronline = fetch_online_status($userinfo, true); 
                    $userinfo['onlinestatuskey'] = $userinfo['onlinestatus']; 
                    $totalcount ++; 
                    eval('$teambits .= "' . fetch_template('siteteam_teambits') . '";'); 
                }  
                unset($teamarray); 

                eval('$meetteams .= "' . fetch_template('siteteam_main') . '";'); 

                    $footer = '<br />'.$meetteams.$footer; 
                }
Reply With Quote
Reply


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

Forum Jump


All times are GMT. The time now is 10:29 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04791 seconds
  • Memory Usage 2,317KB
  • Queries Executed 25 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)bbcode_code
  • (4)bbcode_php
  • (4)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (9)postbit
  • (9)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete