@@ -922,6 +922,10 @@ static inline HashTable *get_ht_for_iap(zval *zv, bool separate) {
922922 php_error_docref (NULL , E_DEPRECATED ,
923923 "Calling %s() on an object is deprecated" , get_active_function_name ());
924924
925+ if (UNEXPECTED (Z_TYPE_P (zv ) != IS_OBJECT )) {
926+ return NULL ;
927+ }
928+
925929 zend_object * zobj = Z_OBJ_P (zv );
926930 if (separate && zobj -> properties && UNEXPECTED (GC_REFCOUNT (zobj -> properties ) > 1 )) {
927931 if (EXPECTED (!(GC_FLAGS (zobj -> properties ) & IS_ARRAY_IMMUTABLE ))) {
@@ -982,7 +986,7 @@ PHP_FUNCTION(end)
982986 ZEND_PARSE_PARAMETERS_END ();
983987
984988 HashTable * array = get_ht_for_iap (array_zv , /* separate */ true);
985- if (zend_hash_num_elements (array ) == 0 ) {
989+ if (! array || zend_hash_num_elements (array ) == 0 ) {
986990 /* array->nInternalPointer is already 0 if the array is empty, even after removing elements */
987991 RETURN_FALSE ;
988992 }
@@ -1004,7 +1008,7 @@ PHP_FUNCTION(prev)
10041008 ZEND_PARSE_PARAMETERS_END ();
10051009
10061010 HashTable * array = get_ht_for_iap (array_zv , /* separate */ true);
1007- if (zend_hash_num_elements (array ) == 0 ) {
1011+ if (! array || zend_hash_num_elements (array ) == 0 ) {
10081012 /* array->nInternalPointer is already 0 if the array is empty, even after removing elements */
10091013 RETURN_FALSE ;
10101014 }
@@ -1026,7 +1030,7 @@ PHP_FUNCTION(next)
10261030 ZEND_PARSE_PARAMETERS_END ();
10271031
10281032 HashTable * array = get_ht_for_iap (array_zv , /* separate */ true);
1029- if (zend_hash_num_elements (array ) == 0 ) {
1033+ if (! array || zend_hash_num_elements (array ) == 0 ) {
10301034 /* array->nInternalPointer is already 0 if the array is empty, even after removing elements */
10311035 RETURN_FALSE ;
10321036 }
@@ -1048,7 +1052,7 @@ PHP_FUNCTION(reset)
10481052 ZEND_PARSE_PARAMETERS_END ();
10491053
10501054 HashTable * array = get_ht_for_iap (array_zv , /* separate */ true);
1051- if (zend_hash_num_elements (array ) == 0 ) {
1055+ if (! array || zend_hash_num_elements (array ) == 0 ) {
10521056 /* array->nInternalPointer is already 0 if the array is empty, even after removing elements */
10531057 RETURN_FALSE ;
10541058 }
@@ -1070,6 +1074,9 @@ PHP_FUNCTION(current)
10701074 ZEND_PARSE_PARAMETERS_END ();
10711075
10721076 HashTable * array = get_ht_for_iap (array_zv , /* separate */ false);
1077+ if (!array ) {
1078+ RETURN_FALSE ;
1079+ }
10731080 php_array_iter_return_current (return_value , array , true);
10741081}
10751082/* }}} */
@@ -1084,6 +1091,9 @@ PHP_FUNCTION(key)
10841091 ZEND_PARSE_PARAMETERS_END ();
10851092
10861093 HashTable * array = get_ht_for_iap (array_zv , /* separate */ false);
1094+ if (!array ) {
1095+ RETURN_NULL ();
1096+ }
10871097 zval * entry = php_array_iter_seek_current (array , true);
10881098 if (EXPECTED (entry )) {
10891099 zend_hash_get_current_key_zval (array , return_value );
0 commit comments