Skip to content

Commit ab87283

Browse files
committed
Merge branch 'PHP-8.2'
2 parents 47ed190 + e3f04dd commit ab87283

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

ext/ffi/tests/arrayPointer.phpt

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
FFI: Test deprecated use of array helper functions on FFI classes doesn't crash
3+
--EXTENSIONS--
4+
ffi
5+
--INI--
6+
ffi.enable=1
7+
--FILE--
8+
<?php
9+
error_reporting(E_ALL & ~E_DEPRECATED);
10+
$data = FFI::new('int');
11+
var_dump(reset($data));
12+
var_dump(end($data));
13+
var_dump(next($data));
14+
var_dump(prev($data));
15+
?>
16+
--EXPECTF--
17+
bool(false)
18+
bool(false)
19+
bool(false)
20+
bool(false)

ext/standard/array.c

+16
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,10 @@ PHP_FUNCTION(end)
10201020
ZEND_PARSE_PARAMETERS_END();
10211021

10221022
HashTable *array = get_ht_for_iap(array_zv, /* separate */ true);
1023+
if (zend_hash_num_elements(array) == 0) {
1024+
/* array->nInternalPointer is already 0 if the array is empty, even after removing elements */
1025+
RETURN_FALSE;
1026+
}
10231027
zend_hash_internal_pointer_end(array);
10241028

10251029
if (USED_RET()) {
@@ -1047,6 +1051,10 @@ PHP_FUNCTION(prev)
10471051
ZEND_PARSE_PARAMETERS_END();
10481052

10491053
HashTable *array = get_ht_for_iap(array_zv, /* separate */ true);
1054+
if (zend_hash_num_elements(array) == 0) {
1055+
/* array->nInternalPointer is already 0 if the array is empty, even after removing elements */
1056+
RETURN_FALSE;
1057+
}
10501058
zend_hash_move_backwards(array);
10511059

10521060
if (USED_RET()) {
@@ -1074,6 +1082,10 @@ PHP_FUNCTION(next)
10741082
ZEND_PARSE_PARAMETERS_END();
10751083

10761084
HashTable *array = get_ht_for_iap(array_zv, /* separate */ true);
1085+
if (zend_hash_num_elements(array) == 0) {
1086+
/* array->nInternalPointer is already 0 if the array is empty, even after removing elements */
1087+
RETURN_FALSE;
1088+
}
10771089
zend_hash_move_forward(array);
10781090

10791091
if (USED_RET()) {
@@ -1101,6 +1113,10 @@ PHP_FUNCTION(reset)
11011113
ZEND_PARSE_PARAMETERS_END();
11021114

11031115
HashTable *array = get_ht_for_iap(array_zv, /* separate */ true);
1116+
if (zend_hash_num_elements(array) == 0) {
1117+
/* array->nInternalPointer is already 0 if the array is empty, even after removing elements */
1118+
RETURN_FALSE;
1119+
}
11041120
zend_hash_internal_pointer_reset(array);
11051121

11061122
if (USED_RET()) {

0 commit comments

Comments
 (0)