Re: array_splice() BUG or Future ?

From: Date: Sat, 06 Apr 2002 00:45:39 +0000
Subject: Re: array_splice() BUG or Future ?
References: 1 2  Groups: php.dev 
Request: Send a blank email to php-dev+get-82160@lists.php.net to get a copy of this message
Kachalov Anton wrote:
I found, that HashTable->arBuckets[*] contained field nKeyLength which equal to zero for all elements and condition: vvvvvvvvvvvvvvvvvv if (p->nKeyLength)
    zend_hash_update(out_hash, p->arKey, p->nKeyLength, &entry,
sizeof(zval *), NULL); ^^^^^^^^^^^^^^^^^^ else
    zend_hash_next_index_insert(out_hash, &entry, sizeof(zval *), NULL);
will fail Is this correct ? Rgds, Anton
I think the idea is "Update if hash key is string. Insert if hash is is numeric". $array = array("32"=>"elem1","54"=>"elem2","23"=>"elem3","92"=>"elem4","3"=>"elem5"); Since hash key is checked if it can be numeric index, so array_splice does change key. as Kachalov pointed out. We might want to add optional parameter to array_splice() and check numeric index also. Andrei, what do you think? -- Yasuo Ohgaki Kachalov Anton wrote:
Hi 2 all! I have some problems with functions, which uses low-level function php_splice() in ext/standard/array.c
This code will produce: Array ( [0] => elem1 [1] => elem2 ) instead of: Array ( [32] => elem1 [54] => elem2 ) <? $array = array("32"=>"elem1","54"=>"elem2","23"=>"elem3","92"=>"elem4","3"=>"elem5");
//print_r($array); outputs array with normal key => data echo "\n\n"; reset($array); array_splice($array, 2); // outputs array with index => data print_r($array); ?> What does it mean ?


« previous php.dev (#82160) next »