PDA

View Full Version : declaring array's


sabret00the
03-13-2005, 03:09 PM
what's the quickest way to find out which arrays you forgot to declare in a script?

Marco van Herwaarden
03-13-2005, 03:51 PM
Rewrite you script and this time decalre all arrays before using them :D

Michael Morris
03-13-2005, 03:56 PM
The print_r function will print out all values of an array and it's indeces. But as Marco pointed out, it's good programming practice to declare all variables at the start of the script. I'd also recommend using unset on the variable first to clear out any injected value.

sabret00the
03-13-2005, 04:48 PM
gah i know theirs an undefined array in here somewhere but i can't find it :(

this does mean undeclared array right?

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

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 2386

Marco van Herwaarden
03-13-2005, 05:43 PM
Well you are passing a variable that is not an array somewhere where an array is expected, that's for sure.

Did you do a:
// 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 calling global?

sabret00the
03-15-2005, 09:32 AM
Well you are passing a variable that is not an array somewhere where an array is expected, that's for sure.

Did you do a:
// 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 calling global?
yup always :(

oh well i'll find it it's in one of two scripts so shouldn't be that hard to find.

Brad
03-15-2005, 03:06 PM
You used to be able to use non-arrays in array_merge, this changed not to long ago in php and now array_merge only accepts arrays.