@@ -89,48 +89,39 @@ U_CFUNC PHP_FUNCTION(datefmt_format_object)
89
89
if (format == NULL || Z_TYPE_P (format) == IS_NULL) {
90
90
// nothing
91
91
} 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);
96
93
if (zend_hash_num_elements (ht) != 2 ) {
97
94
intl_error_set (NULL , U_ILLEGAL_ARGUMENT_ERROR,
98
95
" datefmt_format_object: bad format; if array, it must have "
99
96
" two elements" , 0 );
100
97
RETURN_FALSE;
101
98
}
102
99
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;
108
115
}
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);
124
121
}
125
122
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" );
134
125
} else if (Z_TYPE_P (format) == IS_LONG) {
135
126
if (!valid_format (format)) {
136
127
intl_error_set (NULL , U_ILLEGAL_ARGUMENT_ERROR,
0 commit comments