}
}
idx = HT_HASH_TO_IDX(idx);
- if (ht->nNumUsed - 1 == idx) {
- do {
- ht->nNumUsed--;
- } while (ht->nNumUsed > 0 && (UNEXPECTED(Z_TYPE(ht->arData[ht->nNumUsed-1].val) == IS_UNDEF)));
- }
ht->nNumOfElements--;
if (ht->nInternalPointer == idx || UNEXPECTED(HT_HAS_ITERATORS(ht))) {
uint32_t new_idx;
}
zend_hash_iterators_update(ht, idx, new_idx);
}
+ if (ht->nNumUsed - 1 == idx) {
+ do {
+ ht->nNumUsed--;
+ } while (ht->nNumUsed > 0 && (UNEXPECTED(Z_TYPE(ht->arData[ht->nNumUsed-1].val) == IS_UNDEF)));
+ ht->nInternalPointer = MIN(ht->nInternalPointer, ht->nNumUsed);
+ }
if (p->key) {
zend_string_release(p->key);
}
--- /dev/null
+--TEST--
+Test current() function : internal pointer maintenance at the end of array
+--FILE--
+<?php
+$array = ["foo" => 1, "bar" => 2, "baz" => 3];
+reset($array);
+while ($cur = current($array)) {
+ var_dump($cur);
+ next($array);
+}
+
+unset($array["baz"]);
+$array[] = 4;
+var_dump(current($array));
+?>
+--EXPECT--
+int(1)
+int(2)
+int(3)
+int(4)