Skip to content

Commit e3f04dd

Browse files
committed
Merge branch 'PHP-8.1' into PHP-8.2
2 parents 9f96618 + fe2dc2b commit e3f04dd

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ PHP NEWS
3939
. Fixed bug GH-10292 (Made the default value of the first param of srand() and
4040
mt_srand() unknown). (kocsismate)
4141
. Fix incorrect check in cs_8559_5 in map_from_unicode(). (nielsdos)
42+
. Fix bug GH-9697 for reset/end/next/prev() attempting to move pointer of
43+
properties table for certain internal classes such as FFI classes
4244

4345
02 Feb 2023, PHP 8.2.2
4446

ext/ffi/tests/arrayPointer.phpt

Lines changed: 20 additions & 0 deletions
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

Lines changed: 16 additions & 0 deletions
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)