summaryrefslogtreecommitdiff
path: root/ext/standard/array.c
diff options
context:
space:
mode:
authorBrad LaFountain <rodif_bl@php.net>2002-08-01 04:38:11 +0000
committerBrad LaFountain <rodif_bl@php.net>2002-08-01 04:38:11 +0000
commit4f5bd6b7d44162f2429fb3c97a38b9bcd3a924fe (patch)
tree4c6064720269d33e8b6ba3ddc1f924af2f3158a4 /ext/standard/array.c
parent1ad75f658b940d87a1592e7f83a402deea0f3ec6 (diff)
downloadphp-git-4f5bd6b7d44162f2429fb3c97a38b9bcd3a924fe.tar.gz
made array_shift re-index like it did before previous fix
Diffstat (limited to 'ext/standard/array.c')
-rw-r--r--ext/standard/array.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/ext/standard/array.c b/ext/standard/array.c
index 73a87fb011..5cd62767cb 100644
--- a/ext/standard/array.c
+++ b/ext/standard/array.c
@@ -1662,7 +1662,8 @@ static void _phpi_pop(INTERNAL_FUNCTION_PARAMETERS, int off_the_end)
{
zval **stack, /* Input stack */
**val; /* Value to be popped */
- HashTable *new_hash; /* New stack */
+ char *key = NULL;
+ int key_len, index;
/* Get the arguments and do error-checking */
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &stack) == FAILURE) {
@@ -1689,14 +1690,28 @@ static void _phpi_pop(INTERNAL_FUNCTION_PARAMETERS, int off_the_end)
INIT_PZVAL(return_value);
/* Delete the first or last value */
- new_hash = php_splice(Z_ARRVAL_PP(stack), (off_the_end) ? -1 : 0, 1, NULL, 0, NULL);
- zend_hash_destroy(Z_ARRVAL_PP(stack));
- efree(Z_ARRVAL_PP(stack));
- Z_ARRVAL_PP(stack) = new_hash;
+ zend_hash_get_current_key_ex(Z_ARRVAL_PP(stack), &key, &key_len, &index, 0, NULL);
+ zend_hash_del_key_or_index(Z_ARRVAL_PP(stack), key, key_len, index, (key) ? HASH_DEL_KEY : HASH_DEL_INDEX);
+
+ // If we did a shift... re-index like it did before
+ if(!off_the_end) {
+ HANDLE_BLOCK_INTERRUPTIONS();
+ {
+ int k = 0;
+ Bucket *p = Z_ARRVAL_PP(stack)->pListHead;
+ while (p != NULL) {
+ if (p->nKeyLength == 0)
+ p->h = k++;
+ p = p->pListNext;
+ }
+ Z_ARRVAL_PP(stack)->nNextFreeElement = k+1;
+ zend_hash_rehash(Z_ARRVAL_PP(stack));
+ }
+ HANDLE_UNBLOCK_INTERRUPTIONS();
+ }
}
/* }}} */
-
/* {{{ proto mixed array_pop(array stack)
Pops an element off the end of the array */
PHP_FUNCTION(array_pop)