@@ -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