@@ -125,62 +125,35 @@ U_CFUNC PHP_FUNCTION(intltz_get_unknown)
125125
126126U_CFUNC PHP_FUNCTION (intltz_create_enumeration)
127127{
128- zval *arg = NULL ;
129- StringEnumeration *se = NULL ;
130- intl_error_reset (NULL );
128+ zend_string *timezone = nullptr ;
129+ zend_long timezone_shift = 0 ;
130+ bool is_null = true ;
131+ StringEnumeration *se = nullptr ;
132+ intl_error_reset (nullptr );
131133
132134 /* double indirection to have the zend engine destroy the new zval that
133135 * results from separation */
134136 ZEND_PARSE_PARAMETERS_START (0 , 1 )
135137 Z_PARAM_OPTIONAL
136- Z_PARAM_ZVAL (arg )
138+ Z_PARAM_STR_OR_LONG_OR_NULL (timezone, timezone_shift, is_null )
137139 ZEND_PARSE_PARAMETERS_END ();
138140
139- if (arg == NULL || Z_TYPE_P (arg) == IS_NULL ) {
141+ if (is_null ) {
140142 se = TimeZone::createEnumeration ();
141- } else if (Z_TYPE_P (arg) == IS_LONG) {
142- int_offset:
143- if (UNEXPECTED (Z_LVAL_P (arg) < (zend_long)INT32_MIN ||
144- Z_LVAL_P (arg) > (zend_long)INT32_MAX)) {
145- intl_error_set (NULL , U_ILLEGAL_ARGUMENT_ERROR,
146- " value is out of range" );
147- RETURN_FALSE;
148- } else {
149- se = TimeZone::createEnumeration ((int32_t ) Z_LVAL_P (arg));
150- }
151- } else if (Z_TYPE_P (arg) == IS_DOUBLE) {
152- double_offset:
153- convert_to_long (arg);
154- goto int_offset;
155- } else if (Z_TYPE_P (arg) == IS_OBJECT || Z_TYPE_P (arg) == IS_STRING) {
156- zend_long lval;
157- double dval;
158- if (!try_convert_to_string (arg)) {
143+ } else if (timezone != nullptr ) {
144+ se = TimeZone::createEnumeration (ZSTR_VAL (timezone));
145+ } else {
146+ if (UNEXPECTED (ZEND_LONG_EXCEEDS_INT (timezone_shift))) {
147+ zend_argument_value_error (1 , " must be between %d and %d" , INT32_MIN, INT32_MAX);
159148 RETURN_THROWS ();
160149 }
161- switch (is_numeric_string (Z_STRVAL_P (arg), Z_STRLEN_P (arg), &lval, &dval, 0 )) {
162- case IS_DOUBLE:
163- zval_ptr_dtor (arg);
164- ZVAL_DOUBLE (arg, dval);
165- goto double_offset;
166- case IS_LONG:
167- zval_ptr_dtor (arg);
168- ZVAL_LONG (arg, lval);
169- goto int_offset;
170- }
171- /* else call string version */
172- se = TimeZone::createEnumeration (Z_STRVAL_P (arg));
173- } else {
174- // TODO Should be a TypeError
175- intl_error_set (NULL , U_ILLEGAL_ARGUMENT_ERROR,
176- " invalid argument type" );
177- RETURN_FALSE;
150+ se = TimeZone::createEnumeration (static_cast <int32_t >(timezone_shift));
178151 }
179152
180153 if (se) {
181154 IntlIterator_from_StringEnumeration (se, return_value);
182155 } else {
183- intl_error_set (NULL , U_ILLEGAL_ARGUMENT_ERROR,
156+ intl_error_set (nullptr , U_ILLEGAL_ARGUMENT_ERROR,
184157 " error obtaining enumeration" );
185158 RETVAL_FALSE;
186159 }
0 commit comments