@@ -89,48 +89,39 @@ U_CFUNC PHP_FUNCTION(datefmt_format_object)
8989 if (format == NULL || Z_TYPE_P (format) == IS_NULL) {
9090 // nothing
9191 } else if (Z_TYPE_P (format) == IS_ARRAY) {
92- HashTable *ht = Z_ARRVAL_P (format);
93- uint32_t idx;
94- zval *z;
95-
92+ HashTable *ht = Z_ARRVAL_P (format);
9693 if (zend_hash_num_elements (ht) != 2 ) {
9794 intl_error_set (NULL , U_ILLEGAL_ARGUMENT_ERROR,
9895 " datefmt_format_object: bad format; if array, it must have "
9996 " two elements" , 0 );
10097 RETURN_FALSE;
10198 }
10299
103- idx = 0 ;
104- while (idx < ht->nNumUsed ) {
105- z = &ht->arData [idx].val ;
106- if (Z_TYPE_P (z) != IS_UNDEF) {
107- break ;
100+ uint32_t idx = 0 ;
101+ zval *z;
102+ ZEND_HASH_FOREACH_VAL (ht, z) {
103+ if (!valid_format (z)) {
104+ if (idx == 0 ) {
105+ intl_error_set (NULL , U_ILLEGAL_ARGUMENT_ERROR,
106+ " datefmt_format_object: bad format; the date format (first "
107+ " element of the array) is not valid" , 0 );
108+ } else {
109+ ZEND_ASSERT (idx == 1 && " We checked that there are two elements above" );
110+ intl_error_set (NULL , U_ILLEGAL_ARGUMENT_ERROR,
111+ " datefmt_format_object: bad format; the time format (second "
112+ " element of the array) is not valid" , 0 );
113+ }
114+ RETURN_FALSE;
108115 }
109- idx++;
110- }
111- if (idx >= ht->nNumUsed || !valid_format (z)) {
112- intl_error_set (NULL , U_ILLEGAL_ARGUMENT_ERROR,
113- " datefmt_format_object: bad format; the date format (first "
114- " element of the array) is not valid" , 0 );
115- RETURN_FALSE;
116- }
117- dateStyle = (DateFormat::EStyle)Z_LVAL_P (z);
118-
119- idx++;
120- while (idx < ht->nNumUsed ) {
121- z = &ht->arData [idx].val ;
122- if (Z_TYPE_P (z) != IS_UNDEF) {
123- break ;
116+ if (idx == 0 ) {
117+ dateStyle = (DateFormat::EStyle)Z_LVAL_P (z);
118+ } else {
119+ ZEND_ASSERT (idx == 1 && " We checked that there are two elements above" );
120+ timeStyle = (DateFormat::EStyle)Z_LVAL_P (z);
124121 }
125122 idx++;
126- }
127- if (idx >= ht->nNumUsed || !valid_format (z)) {
128- intl_error_set (NULL , U_ILLEGAL_ARGUMENT_ERROR,
129- " datefmt_format_object: bad format; the time format ("
130- " second element of the array) is not valid" , 0 );
131- RETURN_FALSE;
132- }
133- timeStyle = (DateFormat::EStyle)Z_LVAL_P (z);
123+ } ZEND_HASH_FOREACH_END ();
124+ ZEND_ASSERT (idx == 2 && " We checked that there are two elements above" );
134125 } else if (Z_TYPE_P (format) == IS_LONG) {
135126 if (!valid_format (format)) {
136127 intl_error_set (NULL , U_ILLEGAL_ARGUMENT_ERROR,
0 commit comments