diff options
author | Máté Kocsis <kocsismate@woohoolabs.com> | 2020-08-14 17:36:20 +0200 |
---|---|---|
committer | Máté Kocsis <kocsismate@woohoolabs.com> | 2020-09-01 16:35:56 +0200 |
commit | f7fbc6333ff9a91ffb2f636790657c927b4e3c55 (patch) | |
tree | 0c3ca3db071c9c0052fd43c633279fd0cd9d9127 /ext/intl/calendar | |
parent | 1c56b40a5ce45f598d718cf34e8a265d44f1d9d4 (diff) | |
download | php-git-f7fbc6333ff9a91ffb2f636790657c927b4e3c55.tar.gz |
Add more precise type info for stubs
Closes GH-6005
Diffstat (limited to 'ext/intl/calendar')
-rw-r--r-- | ext/intl/calendar/calendar.stub.php | 3 | ||||
-rw-r--r-- | ext/intl/calendar/calendar_arginfo.h | 4 | ||||
-rw-r--r-- | ext/intl/calendar/calendar_methods.cpp | 39 |
3 files changed, 21 insertions, 25 deletions
diff --git a/ext/intl/calendar/calendar.stub.php b/ext/intl/calendar/calendar.stub.php index bc09ae70a3..5c89535497 100644 --- a/ext/intl/calendar/calendar.stub.php +++ b/ext/intl/calendar/calendar.stub.php @@ -50,11 +50,10 @@ class IntlCalendar public function clear(?int $field = null) {} /** - * @param DateTime|string $dateTime * @return IntlCalendar|null * @alias intlcal_from_date_time */ - public static function fromDateTime($dateTime, ?string $locale = null) {} + public static function fromDateTime(DateTime|string $dateTime, ?string $locale = null) {} /** * @return int diff --git a/ext/intl/calendar/calendar_arginfo.h b/ext/intl/calendar/calendar_arginfo.h index 99626bd19e..f84bf76140 100644 --- a/ext/intl/calendar/calendar_arginfo.h +++ b/ext/intl/calendar/calendar_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 3facb6bdce18efae3d6b9594d1fcddfb220dd54d */ + * Stub hash: 0ac7a1d4e011518fc956fb05624b45b061fa9710 */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_IntlCalendar___construct, 0, 0, 0) ZEND_END_ARG_INFO() @@ -32,7 +32,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_IntlCalendar_clear, 0, 0, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_IntlCalendar_fromDateTime, 0, 0, 1) - ZEND_ARG_INFO(0, dateTime) + ZEND_ARG_OBJ_TYPE_MASK(0, dateTime, DateTime, MAY_BE_STRING, NULL) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, locale, IS_STRING, 1, "null") ZEND_END_ARG_INFO() diff --git a/ext/intl/calendar/calendar_methods.cpp b/ext/intl/calendar/calendar_methods.cpp index df3fc24c61..ed27551d66 100644 --- a/ext/intl/calendar/calendar_methods.cpp +++ b/ext/intl/calendar/calendar_methods.cpp @@ -941,38 +941,35 @@ U_CFUNC PHP_FUNCTION(intlcal_set_skipped_wall_time_option) U_CFUNC PHP_FUNCTION(intlcal_from_date_time) { - zval *zv_arg, - zv_tmp, - *zv_datetime = NULL, - zv_timestamp; + zend_object *date_obj; + zend_string *date_str; + zval zv_tmp, zv_arg, zv_timestamp; php_date_obj *datetime; - char *locale_str = NULL; + char *locale_str = NULL; size_t locale_str_len; TimeZone *timeZone; - UErrorCode status = U_ZERO_ERROR; + UErrorCode status = U_ZERO_ERROR; Calendar *cal; intl_error_reset(NULL); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|s!", - &zv_arg, &locale_str, &locale_str_len) == FAILURE) { - RETURN_THROWS(); - } + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_STR_OR_OBJ_OF_CLASS(date_str, date_obj, php_date_get_date_ce()) + Z_PARAM_OPTIONAL + Z_PARAM_STRING_OR_NULL(locale_str, locale_str_len) + ZEND_PARSE_PARAMETERS_END(); - if (!(Z_TYPE_P(zv_arg) == IS_OBJECT && instanceof_function( - Z_OBJCE_P(zv_arg), php_date_get_date_ce()))) { + if (date_str) { object_init_ex(&zv_tmp, php_date_get_date_ce()); - zend_call_known_instance_method_with_1_params( - Z_OBJCE(zv_tmp)->constructor, Z_OBJ(zv_tmp), NULL, zv_arg); - zv_datetime = &zv_tmp; + ZVAL_STR(&zv_arg, date_str); + zend_call_known_instance_method_with_1_params(Z_OBJCE(zv_tmp)->constructor, Z_OBJ(zv_tmp), NULL, &zv_arg); + date_obj = Z_OBJ(zv_tmp); if (EG(exception)) { zend_object_store_ctor_failed(Z_OBJ(zv_tmp)); goto error; } - } else { - zv_datetime = zv_arg; } - datetime = Z_PHPDATE_P(zv_datetime); + datetime = php_date_obj_from_obj(date_obj); if (!datetime->time) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_from_date_time: DateTime object is unconstructed", @@ -980,7 +977,7 @@ U_CFUNC PHP_FUNCTION(intlcal_from_date_time) goto error; } - zend_call_method_with_0_params(Z_OBJ_P(zv_datetime), php_date_get_date_ce(), NULL, "gettimestamp", &zv_timestamp); + zend_call_method_with_0_params(date_obj, php_date_get_date_ce(), NULL, "gettimestamp", &zv_timestamp); if (Z_TYPE(zv_timestamp) != IS_LONG) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_from_date_time: bad DateTime; call to " @@ -1023,8 +1020,8 @@ U_CFUNC PHP_FUNCTION(intlcal_from_date_time) calendar_object_create(return_value, cal); error: - if (zv_datetime && zv_datetime != zv_arg) { - zval_ptr_dtor(zv_datetime); + if (date_str) { + OBJ_RELEASE(date_obj); } } |