Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions ext/intl/php_intl.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,7 @@ function intltz_count_equivalent_ids(string $timezoneId): int|false {}

function intltz_create_default(): IntlTimeZone {}

/** @param IntlTimeZone|string|int|float|null $countryOrRawOffset */
function intltz_create_enumeration($countryOrRawOffset = null): IntlIterator|false {}
function intltz_create_enumeration(string|int|null $countryOrRawOffset = null): IntlIterator|false {}

function intltz_create_time_zone(string $timezoneId): ?IntlTimeZone {}

Expand Down
4 changes: 2 additions & 2 deletions ext/intl/php_intl_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 14 additions & 5 deletions ext/intl/tests/timezone_createEnumeration_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,19 @@ IntlTimeZone::createEnumeration(): errors
intl
--FILE--
<?php
ini_set("intl.error_level", E_WARNING);

var_dump(IntlTimeZone::createEnumeration(array()));
try {
var_dump(IntlTimeZone::createEnumeration([]));
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

try {
var_dump(IntlTimeZone::createEnumeration(new stdClass()));
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
?>
--EXPECTF--
Warning: IntlTimeZone::createEnumeration(): invalid argument type in %s on line %d
bool(false)
--EXPECT--
TypeError: IntlTimeZone::createEnumeration(): Argument #1 ($countryOrRawOffset) must be of type string|int|null, array given
TypeError: IntlTimeZone::createEnumeration(): Argument #1 ($countryOrRawOffset) must be of type string|int|null, stdClass given
3 changes: 1 addition & 2 deletions ext/intl/timezone/timezone.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,10 @@ public static function countEquivalentIDs(string $timezoneId): int|false {}
public static function createDefault(): IntlTimeZone {}

/**
* @param IntlTimeZone|string|int|float|null $countryOrRawOffset
* @tentative-return-type
* @alias intltz_create_enumeration
*/
public static function createEnumeration($countryOrRawOffset = null): IntlIterator|false {}
public static function createEnumeration(string|int|null $countryOrRawOffset = null): IntlIterator|false {}

/**
* @tentative-return-type
Expand Down
4 changes: 2 additions & 2 deletions ext/intl/timezone/timezone_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 14 additions & 41 deletions ext/intl/timezone/timezone_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,62 +125,35 @@ U_CFUNC PHP_FUNCTION(intltz_get_unknown)

U_CFUNC PHP_FUNCTION(intltz_create_enumeration)
{
zval *arg = NULL;
StringEnumeration *se = NULL;
intl_error_reset(NULL);
zend_string *timezone = nullptr;
zend_long timezone_shift = 0;
bool is_null = true;
StringEnumeration *se = nullptr;
intl_error_reset(nullptr);

/* double indirection to have the zend engine destroy the new zval that
* results from separation */
ZEND_PARSE_PARAMETERS_START(0, 1)
Z_PARAM_OPTIONAL
Z_PARAM_ZVAL(arg)
Z_PARAM_STR_OR_LONG_OR_NULL(timezone, timezone_shift, is_null)
ZEND_PARSE_PARAMETERS_END();

if (arg == NULL || Z_TYPE_P(arg) == IS_NULL) {
if (is_null) {
se = TimeZone::createEnumeration();
} else if (Z_TYPE_P(arg) == IS_LONG) {
int_offset:
if (UNEXPECTED(Z_LVAL_P(arg) < (zend_long)INT32_MIN ||
Z_LVAL_P(arg) > (zend_long)INT32_MAX)) {
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
"value is out of range");
RETURN_FALSE;
} else {
se = TimeZone::createEnumeration((int32_t) Z_LVAL_P(arg));
}
} else if (Z_TYPE_P(arg) == IS_DOUBLE) {
double_offset:
convert_to_long(arg);
goto int_offset;
} else if (Z_TYPE_P(arg) == IS_OBJECT || Z_TYPE_P(arg) == IS_STRING) {
zend_long lval;
double dval;
if (!try_convert_to_string(arg)) {
} else if (timezone != nullptr) {
se = TimeZone::createEnumeration(ZSTR_VAL(timezone));
} else {
if (UNEXPECTED(ZEND_LONG_EXCEEDS_INT(timezone_shift))) {
zend_argument_value_error(1, "must be between %d and %d", INT32_MIN, INT32_MAX);
RETURN_THROWS();
}
switch (is_numeric_string(Z_STRVAL_P(arg), Z_STRLEN_P(arg), &lval, &dval, 0)) {
case IS_DOUBLE:
zval_ptr_dtor(arg);
ZVAL_DOUBLE(arg, dval);
goto double_offset;
case IS_LONG:
zval_ptr_dtor(arg);
ZVAL_LONG(arg, lval);
goto int_offset;
}
/* else call string version */
se = TimeZone::createEnumeration(Z_STRVAL_P(arg));
} else {
// TODO Should be a TypeError
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
"invalid argument type");
RETURN_FALSE;
se = TimeZone::createEnumeration(static_cast<int32_t>(timezone_shift));
}

if (se) {
IntlIterator_from_StringEnumeration(se, return_value);
} else {
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
intl_error_set(nullptr, U_ILLEGAL_ARGUMENT_ERROR,
"error obtaining enumeration");
RETVAL_FALSE;
}
Expand Down