@@ -1029,19 +1029,31 @@ static inline HashTable *get_ht_for_iap(zval *zv, bool separate) {
10291029 return zobj -> handlers -> get_properties (zobj );
10301030}
10311031
1032- static void ia_return_current (zval * return_value , HashTable * array )
1032+ static void ia_return_current (zval * return_value , HashTable * array , bool forward_direction )
10331033{
10341034 zval * entry ;
10351035
1036- if ((entry = zend_hash_get_current_data (array )) == NULL ) {
1037- RETURN_FALSE ;
1038- }
1036+ while (true) {
1037+ if ((entry = zend_hash_get_current_data (array )) == NULL ) {
1038+ RETURN_FALSE ;
1039+ }
10391040
1040- ZVAL_DEINDIRECT (entry );
1041+ ZVAL_DEINDIRECT (entry );
10411042
1042- /* Possible with an uninitialized typed property */
1043- if (Z_TYPE_P (entry ) == IS_UNDEF ) {
1044- RETURN_FALSE ;
1043+ /* Possible with an uninitialized typed property */
1044+ if (UNEXPECTED (Z_TYPE_P (entry ) == IS_UNDEF )) {
1045+ zend_result result ;
1046+ if (forward_direction ) {
1047+ result = zend_hash_move_forward (array );
1048+ } else {
1049+ result = zend_hash_move_backwards (array );
1050+ }
1051+ if (result != SUCCESS ) {
1052+ RETURN_FALSE ;
1053+ }
1054+ } else {
1055+ break ;
1056+ }
10451057 }
10461058
10471059 RETURN_COPY_DEREF (entry );
@@ -1064,7 +1076,7 @@ PHP_FUNCTION(end)
10641076 zend_hash_internal_pointer_end (array );
10651077
10661078 if (USED_RET ()) {
1067- ia_return_current (return_value , array );
1079+ ia_return_current (return_value , array , false );
10681080 }
10691081}
10701082/* }}} */
@@ -1086,7 +1098,7 @@ PHP_FUNCTION(prev)
10861098 zend_hash_move_backwards (array );
10871099
10881100 if (USED_RET ()) {
1089- ia_return_current (return_value , array );
1101+ ia_return_current (return_value , array , false );
10901102 }
10911103}
10921104/* }}} */
@@ -1108,7 +1120,7 @@ PHP_FUNCTION(next)
11081120 zend_hash_move_forward (array );
11091121
11101122 if (USED_RET ()) {
1111- ia_return_current (return_value , array );
1123+ ia_return_current (return_value , array , true );
11121124 }
11131125}
11141126/* }}} */
@@ -1130,7 +1142,7 @@ PHP_FUNCTION(reset)
11301142 zend_hash_internal_pointer_reset (array );
11311143
11321144 if (USED_RET ()) {
1133- ia_return_current (return_value , array );
1145+ ia_return_current (return_value , array , true );
11341146 }
11351147}
11361148/* }}} */
@@ -1145,7 +1157,7 @@ PHP_FUNCTION(current)
11451157 ZEND_PARSE_PARAMETERS_END ();
11461158
11471159 HashTable * array = get_ht_for_iap (array_zv , /* separate */ false);
1148- ia_return_current (return_value , array );
1160+ ia_return_current (return_value , array , true );
11491161}
11501162/* }}} */
11511163
0 commit comments