Skip to content

Commit 85675f4

Browse files
committed
ext/int: IntlTimeZone converting few intl error to exceptions.
1 parent 9603199 commit 85675f4

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

ext/intl/tests/timezone_createEnumeration_error.phpt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ intl
66
<?php
77
ini_set("intl.error_level", E_WARNING);
88

9-
var_dump(IntlTimeZone::createEnumeration(array()));
9+
try {
10+
IntlTimeZone::createEnumeration(array());
11+
} catch (TypeError $e) {
12+
echo $e->getMessage() . PHP_EOL;
13+
}
1014
?>
11-
--EXPECTF--
12-
Warning: IntlTimeZone::createEnumeration(): invalid argument type in %s on line %d
13-
bool(false)
15+
--EXPECT--
16+
IntlTimeZone::createEnumeration(): Argument #1 ($countryOrRawOffset) invalid argument type

ext/intl/timezone/timezone_methods.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,7 @@ U_CFUNC PHP_FUNCTION(intltz_from_date_time_zone)
8383

8484
tzobj = Z_PHPTIMEZONE_P(zv_timezone);
8585
if (!tzobj->initialized) {
86-
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
87-
"DateTimeZone object is unconstructed",
88-
0);
86+
zend_throw_error(NULL, "DateTimeZone object is unconstructed");
8987
RETURN_NULL();
9088
}
9189

@@ -150,9 +148,8 @@ U_CFUNC PHP_FUNCTION(intltz_create_enumeration)
150148
int_offset:
151149
if (UNEXPECTED(Z_LVAL_P(arg) < (zend_long)INT32_MIN ||
152150
Z_LVAL_P(arg) > (zend_long)INT32_MAX)) {
153-
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
154-
"value is out of range", 0);
155-
RETURN_FALSE;
151+
zend_argument_value_error(1, "value is out of range");
152+
RETURN_THROWS();
156153
} else {
157154
se = TimeZone::createEnumeration((int32_t) Z_LVAL_P(arg));
158155
}
@@ -179,9 +176,8 @@ U_CFUNC PHP_FUNCTION(intltz_create_enumeration)
179176
/* else call string version */
180177
se = TimeZone::createEnumeration(Z_STRVAL_P(arg));
181178
} else {
182-
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
183-
"invalid argument type", 0);
184-
RETURN_FALSE;
179+
zend_argument_type_error(1, "invalid argument type");
180+
RETURN_THROWS();
185181
}
186182

187183
if (se) {
@@ -242,9 +238,8 @@ U_CFUNC PHP_FUNCTION(intltz_create_time_zone_id_enumeration)
242238

243239
if (!arg3isnull) {
244240
if (UNEXPECTED(offset_arg < (zend_long)INT32_MIN || offset_arg > (zend_long)INT32_MAX)) {
245-
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
246-
"offset out of bounds", 0);
247-
RETURN_FALSE;
241+
zend_argument_value_error(3, "offset out of bounds");
242+
RETURN_THROWS();
248243
}
249244
offset = (int32_t)offset_arg;
250245
offsetp = &offset;
@@ -349,7 +344,8 @@ U_CFUNC PHP_FUNCTION(intltz_get_equivalent_id)
349344
}
350345

351346
if (UNEXPECTED(index < (zend_long)INT32_MIN || index > (zend_long)INT32_MAX)) {
352-
RETURN_FALSE;
347+
zend_argument_value_error(2, "index out of range");
348+
RETURN_THROWS();
353349
}
354350

355351
UErrorCode status = UErrorCode();

0 commit comments

Comments
 (0)