PDA

View Full Version : php5 and the change of array_merge


reteep
01-07-2005, 12:00 PM
Hey there,


Warning: array_merge() [function.array-merge]: Argument #2 is not an array in /*/vb/includes/init.php on line 522

It's a common Error for people (like me) who are running php5 and lots of hacks are affected.

Now I searched through the forum and found lots of topics about it, however there's no common fix so far.

In fact it should be possible to replace all that array_merge functions with the new one, isn't it? How would that look like by example?

Xenon
01-07-2005, 12:09 PM
actually the fix is very easy:

make sure all your files have

// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();

// get special data templates from the datastore
$specialtemplates = array();

// pre-cache templates used by all actions
$globaltemplates = array();

// pre-cache templates used by specific actions
$actiontemplates = array();

before they call global.php

reteep
01-07-2005, 12:13 PM
Ahh, good to know.

Thanks for your post!

Xenon
01-07-2005, 12:32 PM
keine ursache :)

Revan
01-07-2005, 11:42 PM
Aber hacks vielleicht hat andere array's dass array_merge gebrauchen, aber nicht eine "if (!is_array($neededarray))" hat? ;)

Ok, now you probably understand why I only get a C in german.

But hacks possibly have other arrays that uses the array_merge, but don't have an "if (!is_array($neededarray))"? ;)

Xenon
01-08-2005, 11:59 AM
@Fillip: don't ask who i got in english classes ^^

The Realist
01-26-2005, 10:59 AM
Sorry for jumping in on someone elses thread........... but interesting read.

I did not think that PHP 5 causes problems like this. I have been scratching my head for days and then I read this post.

I have a similar problem as follows:

I installed a few hacks and all was fine until I noticed errors are the top of some pages. This error below is from the top of my arcade hack:


Warning: array_merge() [function.array-merge]: Argument #1 is not an array in /global.php on line 376

Warning: Invalid argument supplied for foreach() in /includes/functions.php on line 2188


Is this problem with PHP 5 cos Im running 5.0.3 thats causing my errors? and if so how do I fix it.

Regards.

actually the fix is very easy:

make sure all your files have

// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();

// get special data templates from the datastore
$specialtemplates = array();

// pre-cache templates used by all actions
$globaltemplates = array();

// pre-cache templates used by specific actions
$actiontemplates = array();

before they call global.php

Well I be bugger :)

Placed the code above that Xenon posted in my global and functions php files ane the errors are now gone and all is working.

Where else should I place this code?

Thanks

noppid
01-26-2005, 11:25 AM
Declaring Variables before using them? What a novel idea! ;)

sabret00the
01-26-2005, 11:52 AM
Declaring Variables before using them? What a novel idea! ;)
why do i always find the worst jokes so hilarious.

noppid
01-26-2005, 12:01 PM
why do i always find the worst jokes so hilarious.

I just have this sick sense of humor and sitting here alone I amuse myself by pointing out the obvious.

If you are a C programmer it might be funny. ;)

No ill intent meant. Just amusing myself.

To be more on topic while I'm having fun, this is usually a hot topic, talking about declaring variables. I found alot of debate on the subject, some very amusing, when after using C for a long time, I had a need to mod some Visual Basic code.

Well off I went and got vB6 and a book. Installed it and did some set up. Now if you have a C background, you can't help yourself, you declare variables, there's no way around it. So I set up the code to not allow dynamic declaration of variables and attemped a complie. It did nothing but complain. Nothing was declared. So to mod this huge piece of code I just removed the statement that made the compiler force declarations. And I was off to delveoping all the bad habits C programmers joke about.

Now I use php, same thing, back to bad habits. Opps, I need a variable here and bam, there it is. I do try to init variables usually, but If you look at any code I wrote, I'm inconsistant. SO part of the amusment above was on myself, I know better and don't do it.

So now php 5 seems to need Array() declared/initialized for this function to accept them. Are we going to declarations in php as a whole? Isn't there a performance benefit to delcaration and proper address space allocated without the compiler having to dynamically sort out types?

I don't hang out at php.net or anywhere that discusses such things, so this thread has sparked my curiousity.

sabret00the
01-26-2005, 01:13 PM
I just have this sick sense of humor and sitting here alone I amuse myself by pointing out the obvious.
nah i actually genuinely laughed bacause i actually knew this was neede for vB3'ing and ignored it and am gonna have to go back through a whole project just to check :(

although i never coded c or any other language bar pascal so i just liked the sarcasm

Xenon
01-26-2005, 03:33 PM
well i don't think, php will make variable declarations needed.

it just removes some of the autocasts that is where the error above comes from.
in php4 an unset variable was casted to an array, when using array_merge.

well, proper coding skills will prevent those errors, so i think it's a step forward :)

Zachery
01-26-2005, 03:46 PM
3.0.6 should have fixed the php5 issues.

Xenon
01-26-2005, 04:16 PM
noooooooooooooooooooooooo

it was good to force better coding skills
bad devs, very bad devs