Bug #69166 [Opn]: Assigning array_values() to array does not reset key counter

From: Date: Tue, 03 Mar 2015 09:02:17 +0000
Subject: Bug #69166 [Opn]: Assigning array_values() to array does not reset key counter
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-191075@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69166&edit=1

 ID:                 69166
 Updated by:         reeze@php.net
 Reported by:        cweiske@php.net
 Summary:            Assigning array_values() to array does not reset key
                     counter
 Status:             Open
 Type:               Bug
 Package:            Arrays related
 PHP Version:        master-Git-2015-03-03 (Git)
 Block user comment: N
 Private report:     N

 New Comment:

This should works:

diff --git a/Zend/zend_hash.h b/Zend/zend_hash.h
index afa3602..30e0453 100644
--- a/Zend/zend_hash.h
+++ b/Zend/zend_hash.h
@@ -795,7 +795,7 @@ static zend_always_inline void *zend_hash_get_current_data_ptr_ex(HashTable *ht,
 #define ZEND_HASH_FILL_END() \
 		__fill_ht->nNumUsed = __fill_idx; \
 		__fill_ht->nNumOfElements = __fill_idx; \
-		__fill_ht->nNextFreeElement = __fill_idx + 1; \
+		__fill_ht->nNextFreeElement = __fill_idx; \
 		__fill_ht->nInternalPointer = 0; \
 	} while (0)
 

I will send a PR soon, could you please try this patch?


Previous Comments:
------------------------------------------------------------------------
[2015-03-03 07:56:58] cweiske@php.net

Also see http://3v4l.org/s5fJX

------------------------------------------------------------------------
[2015-03-03 07:52:19] cweiske@php.net

Description:
------------
When assigning the result of array_values() to an array variable, its internal key counter does not
get reset anymore as it did on PHP 4 and PHP 5.

Test script:
---------------
<?php
$ar = array('foo');
unset($ar[0]);
$ar = array_values($ar);
$ar[] = 'bar';
var_dump($ar);
?>

Expected result:
----------------
array(1) {
  [0] =>
  string(3) "bar"
}


Actual result:
--------------
array(1) {
  [1]=>
  string(3) "bar"
}


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=69166&edit=1


Thread (4 messages)

« previous php.bugs (#191075) next »