mirror of
https://github.com/php/php-src.git
synced 2025-08-15 13:38:49 +02:00
Merge branch 'PHP-8.4'
* PHP-8.4: Fix GH-16957: Assertion failure in array_shift with self-referencing array
This commit is contained in:
commit
563da1b9d2
2 changed files with 49 additions and 2 deletions
|
@ -3632,7 +3632,8 @@ PHP_FUNCTION(array_shift)
|
|||
}
|
||||
idx++;
|
||||
}
|
||||
RETVAL_COPY_DEREF(val);
|
||||
RETVAL_COPY_VALUE(val);
|
||||
ZVAL_UNDEF(val);
|
||||
|
||||
/* Delete the first value */
|
||||
zend_hash_packed_del_val(Z_ARRVAL_P(stack), val);
|
||||
|
@ -3686,7 +3687,8 @@ PHP_FUNCTION(array_shift)
|
|||
}
|
||||
idx++;
|
||||
}
|
||||
RETVAL_COPY_DEREF(val);
|
||||
RETVAL_COPY_VALUE(val);
|
||||
ZVAL_UNDEF(val);
|
||||
|
||||
/* Delete the first value */
|
||||
zend_hash_del_bucket(Z_ARRVAL_P(stack), p);
|
||||
|
@ -3710,6 +3712,10 @@ PHP_FUNCTION(array_shift)
|
|||
}
|
||||
|
||||
zend_hash_internal_pointer_reset(Z_ARRVAL_P(stack));
|
||||
|
||||
if (Z_ISREF_P(return_value)) {
|
||||
zend_unwrap_reference(return_value);
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
|
41
ext/standard/tests/array/gh16957.phpt
Normal file
41
ext/standard/tests/array/gh16957.phpt
Normal file
|
@ -0,0 +1,41 @@
|
|||
--TEST--
|
||||
GH-16957 (Assertion failure in array_shift with self-referencing array)
|
||||
--FILE--
|
||||
<?php
|
||||
$new_array = array(&$new_array, 1, 'two');
|
||||
var_dump($shifted = array_shift($new_array));
|
||||
var_dump($new_array);
|
||||
var_dump($new_array === $shifted);
|
||||
|
||||
$new_array2 = array(&$new_array2, 2 => 1, 300 => 'two');
|
||||
var_dump($shifted = array_shift($new_array2));
|
||||
var_dump($new_array2);
|
||||
var_dump($new_array2 === $shifted);
|
||||
?>
|
||||
--EXPECT--
|
||||
array(2) {
|
||||
[0]=>
|
||||
int(1)
|
||||
[1]=>
|
||||
string(3) "two"
|
||||
}
|
||||
array(2) {
|
||||
[0]=>
|
||||
int(1)
|
||||
[1]=>
|
||||
string(3) "two"
|
||||
}
|
||||
bool(true)
|
||||
array(2) {
|
||||
[0]=>
|
||||
int(1)
|
||||
[1]=>
|
||||
string(3) "two"
|
||||
}
|
||||
array(2) {
|
||||
[0]=>
|
||||
int(1)
|
||||
[1]=>
|
||||
string(3) "two"
|
||||
}
|
||||
bool(true)
|
Loading…
Add table
Add a link
Reference in a new issue