]> granicus.if.org Git - php/commitdiff
Use new params API for throwable constructors in date
authorSara Golemon <pollita@php.net>
Wed, 28 Dec 2016 19:18:46 +0000 (11:18 -0800)
committerSara Golemon <pollita@php.net>
Fri, 30 Dec 2016 02:26:27 +0000 (18:26 -0800)
ext/date/php_date.c

index 5120df13f747c60f2f0cae9742b81913848133cf..5a839e3a52b3967813c3c5b84c8064d5773a0a13 100644 (file)
@@ -2768,9 +2768,11 @@ PHP_METHOD(DateTime, __construct)
        size_t time_str_len = 0;
        zend_error_handling error_handling;
 
-       if (FAILURE == zend_parse_parameters_throw(ZEND_NUM_ARGS(), "|sO!", &time_str, &time_str_len, &timezone_object, date_ce_timezone)) {
-               return;
-       }
+       ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 0, 2)
+               Z_PARAM_OPTIONAL
+               Z_PARAM_STRING(time_str, time_str_len)
+               Z_PARAM_OBJECT_OF_CLASS_EX(timezone_object, date_ce_timezone, 1, 0)
+       ZEND_PARSE_PARAMETERS_END();
 
        zend_replace_error_handling(EH_THROW, NULL, &error_handling);
        php_date_initialize(Z_PHPDATE_P(getThis()), time_str, time_str_len, NULL, timezone_object, 1);
@@ -2788,9 +2790,11 @@ PHP_METHOD(DateTimeImmutable, __construct)
        size_t time_str_len = 0;
        zend_error_handling error_handling;
 
-       if (FAILURE == zend_parse_parameters_throw(ZEND_NUM_ARGS(), "|sO!", &time_str, &time_str_len, &timezone_object, date_ce_timezone)) {
-               return;
-       }
+       ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 0, 2)
+               Z_PARAM_OPTIONAL
+               Z_PARAM_STRING(time_str, time_str_len)
+               Z_PARAM_OBJECT_OF_CLASS_EX(timezone_object, date_ce_timezone, 1, 0)
+       ZEND_PARSE_PARAMETERS_END();
 
        zend_replace_error_handling(EH_THROW, NULL, &error_handling);
        php_date_initialize(Z_PHPDATE_P(getThis()), time_str, time_str_len, NULL, timezone_object, 1);
@@ -3767,18 +3771,17 @@ PHP_FUNCTION(timezone_open)
 */
 PHP_METHOD(DateTimeZone, __construct)
 {
-       char *tz;
-       size_t tz_len;
+       zend_string *tz;
        php_timezone_obj *tzobj;
        zend_error_handling error_handling;
 
-       if (FAILURE == zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s", &tz, &tz_len)) {
-               return;
-       }
+       ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 1, 1)
+               Z_PARAM_STR(tz)
+       ZEND_PARSE_PARAMETERS_END();
 
        zend_replace_error_handling(EH_THROW, NULL, &error_handling);
        tzobj = Z_PHPTIMEZONE_P(getThis());
-       timezone_initialize(tzobj, tz, tz_len);
+       timezone_initialize(tzobj, ZSTR_VAL(tz), ZSTR_LEN(tz));
        zend_restore_error_handling(&error_handling);
 }
 /* }}} */
@@ -4214,18 +4217,17 @@ void date_interval_write_property(zval *object, zval *member, zval *value, void
 */
 PHP_METHOD(DateInterval, __construct)
 {
-       char *interval_string = NULL;
-       size_t   interval_string_length;
+       zend_string *interval_string = NULL;
        php_interval_obj *diobj;
        timelib_rel_time *reltime;
        zend_error_handling error_handling;
 
-       if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s", &interval_string, &interval_string_length) == FAILURE) {
-               return;
-       }
+       ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 1, 1)
+               Z_PARAM_STR(interval_string)
+       ZEND_PARSE_PARAMETERS_END();
 
        zend_replace_error_handling(EH_THROW, NULL, &error_handling);
-       if (date_interval_initialize(&reltime, interval_string, interval_string_length) == SUCCESS) {
+       if (date_interval_initialize(&reltime, ZSTR_VAL(interval_string), ZSTR_LEN(interval_string)) == SUCCESS) {
                diobj = Z_PHPINTERVAL_P(getThis());
                diobj->diff = reltime;
                diobj->initialized = 1;