--- /dev/null
+--TEST--
+Bug #47836 (array operator [] inconsistency when the array has PHP_INT_MAX index value)
+--FILE--
+<?php
+
+$arr[PHP_INT_MAX] = 1;
+$arr[] = 2;
+
+var_dump($arr);
+?>
+--EXPECTF--
+Warning: Cannot add element to the array as the next element is already occupied in %s on line 4
+array(1) {
+ [%d]=>
+ int(1)
+}
UPDATE_DATA(ht, p, pData, nDataSize);
HANDLE_UNBLOCK_INTERRUPTIONS();
if ((long)h >= (long)ht->nNextFreeElement) {
- ht->nNextFreeElement = h + 1;
+ ht->nNextFreeElement = h < LONG_MAX ? h + 1 : LONG_MAX;
}
if (pDest) {
*pDest = p->pData;
HANDLE_UNBLOCK_INTERRUPTIONS();
if ((long)h >= (long)ht->nNextFreeElement) {
- ht->nNextFreeElement = h + 1;
+ ht->nNextFreeElement = h < LONG_MAX ? h + 1 : LONG_MAX;
}
ht->nNumOfElements++;
ZEND_HASH_IF_FULL_DO_RESIZE(ht);
--TEST--
-Test array_push() function : error conditions - min and max int values as keys
+Test array_push() function : error conditions - max int value as key
--FILE--
<?php
/* Prototype : int array_push(array $stack, mixed $var [, mixed $...])
*/
/*
- * Use PHP's minimum and maximum integer values as array keys
+ * Use PHP's maximum integer value as array key
* then try and push new elements onto the array
*/
echo "*** Testing array_push() : error conditions ***\n";
-$array = array(-PHP_INT_MAX => 'min', PHP_INT_MAX => 'max');
+$array = array(PHP_INT_MAX => 'max');
var_dump(array_push($array, 'new'));
var_dump($array);
-var_dump(array_push($array, 'var'));
-var_dump($array);
echo "Done";
?>
--EXPECTF--
*** Testing array_push() : error conditions ***
-int(3)
-array(3) {
- [-%d]=>
- string(3) "min"
- [%d]=>
- string(3) "max"
- [-%d]=>
- string(3) "new"
-}
Warning: array_push(): Cannot add element to the array as the next element is already occupied in %s on line %d
bool(false)
-array(3) {
- [-%d]=>
- string(3) "min"
+array(1) {
[%d]=>
string(3) "max"
- [-%d]=>
- string(3) "new"
}
Done
\ No newline at end of file