Multi dimensional arrays
| From: | Roel Bouwman | Date: | Mon, 11 Oct 1999 10:22:22 +0000 |
| Subject: | Multi dimensional arrays | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-11682@lists.php.net to get a copy of this message | ||
Hi there,
I have a problem reading and returning multi dimensional arrays in a
PHP function.
My code segfaults when I attempt to read out the pval->value.str.val field
for a pval record retrieved from an array, which in turn was an entry
in an array.
e.g.:
void php3_wol_queryserver(INTERNAL_FUNCTION_PARAMETERS)
{
pval *servers, *attribs;
pval *item, *item2;
if (ARG_COUNT(ht)!=2 || getParameters(ht, 2, &servers, &attribs)==FAILURE) {
WRONG_PARAM_COUNT;
}
_php3_hash_internal_pointer_reset(attribs->value.ht); /* Is this really neccesary? */
while (_php3_hash_get_current_data(attribs->value.ht, (void**)&item)!=FAILURE) {
char *skey;
ulong nkey;
if (item->type==IS_ARRAY) {
if (_php3_hash_get_current_key(attribs->value.ht, &skey, &nkey)==HASH_KEY_IS_LONG)
{
php3_error(E_WARNING, "Parameter for key %d is array", nkey);
// nkey is the type of the attribute, item->value.ht holds a hash with values for this
key
_php3_hash_internal_pointer_reset(item->value.ht);
while (_php3_hash_get_current_data(item->value.ht, (void**)&item2)!=FAILURE) {
at=(ATTRIB*)realloc(at, ++atcount*sizeof(ATTRIB));
if (item2->type==IS_STRING) {
/* Segfault occurs in the following function, where the value of this item is used
(it's NULL) */
php3_error(E_WARNING, "Setting attribute with key %s and value %s", nkey,
item2->value.str.val);
SetAttribute(&at[atcount-1], nkey, TYPESTRING, strdup(item2->value.str.val), 0);
} else {
php3_error(E_WARNING, "Got so far..");
php3_error(E_WARNING, "Setting attribute with key %s and value %d", nkey,
item2->value.lval);
SetAttribute(&at[atcount-1], nkey, TYPEINTEGER, &item2->value.lval, 0);
}
_php3_hash_move_forward(item->value.ht);
}
} else php3_error(E_WARNING, "Invalid attribute in array, ignoring");
}
_php3_hash_move_forward(attribs->value.ht);
}
}
What am I doing wrong?
Regards,
Roel Bouwman.
--
Roel Bouwman
WorldOnline Application Development
roelb@worldonline.nl