diff --git a/ext/date/php_date.c b/ext/date/php_date.c index ed89c9d494a6f..a533552621f2a 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -673,7 +673,7 @@ static const char *php_date_short_day_name(timelib_sll y, timelib_sll m, timelib /* }}} */ /* {{{ date_format - (gm)date helper */ -static zend_string *date_format(const char *format, size_t format_len, timelib_time *t, bool localtime) +static zend_string *date_format(const char *format, size_t format_len, const timelib_time *t, bool localtime) { smart_str string = {0}; size_t i; @@ -845,7 +845,7 @@ static zend_string *date_format(const char *format, size_t format_len, timelib_t return string.s; } -PHPAPI zend_string *php_format_date_obj(const char *format, size_t format_len, php_date_obj *date_obj) +PHPAPI zend_string *php_format_date_obj(const char *format, size_t format_len, const php_date_obj *date_obj) { if (!date_obj->time) { return NULL; @@ -2807,7 +2807,7 @@ PHP_METHOD(DateTimeImmutable, createFromTimestamp) } /* }}} */ -static bool php_date_initialize_from_hash(php_date_obj **dateobj, HashTable *myht) +static bool php_date_initialize_from_hash(php_date_obj **dateobj, const HashTable *myht) { zval *z_date; zval *z_timezone_type; @@ -2948,7 +2948,7 @@ PHP_METHOD(DateTimeImmutable, __serialize) } /* }}} */ -static bool date_time_is_internal_property(zend_string *name) +static bool date_time_is_internal_property(const zend_string *name) { if ( zend_string_equals_literal(name, "date") || @@ -2960,7 +2960,7 @@ static bool date_time_is_internal_property(zend_string *name) return 0; } -static void restore_custom_datetime_properties(zval *object, HashTable *myht) +static void restore_custom_datetime_properties(zval *object, const HashTable *myht) { zend_string *prop_name; zval *prop_val; @@ -2978,15 +2978,13 @@ PHP_METHOD(DateTime, __unserialize) { zval *object = ZEND_THIS; php_date_obj *dateobj; - zval *array; HashTable *myht; ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_ARRAY(array) + Z_PARAM_ARRAY_HT(myht) ZEND_PARSE_PARAMETERS_END(); dateobj = Z_PHPDATE_P(object); - myht = Z_ARRVAL_P(array); if (!php_date_initialize_from_hash(&dateobj, myht)) { zend_throw_error(NULL, "Invalid serialization data for DateTime object"); @@ -3002,15 +3000,13 @@ PHP_METHOD(DateTimeImmutable, __unserialize) { zval *object = ZEND_THIS; php_date_obj *dateobj; - zval *array; HashTable *myht; ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_ARRAY(array) + Z_PARAM_ARRAY_HT(myht) ZEND_PARSE_PARAMETERS_END(); dateobj = Z_PHPDATE_P(object); - myht = Z_ARRVAL_P(array); if (!php_date_initialize_from_hash(&dateobj, myht)) { zend_throw_error(NULL, "Invalid serialization data for DateTimeImmutable object"); @@ -3027,7 +3023,7 @@ static void php_do_date_time_wakeup(INTERNAL_FUNCTION_PARAMETERS, const char *cl { zval *object = ZEND_THIS; php_date_obj *dateobj; - HashTable *myht; + const HashTable *myht; ZEND_PARSE_PARAMETERS_NONE(); @@ -3057,7 +3053,7 @@ PHP_METHOD(DateTimeImmutable, __wakeup) /* }}} */ /* Helper function used to add an associative array of warnings and errors to a zval */ -static void zval_from_error_container(zval *z, timelib_error_container *error) /* {{{ */ +static void zval_from_error_container(zval *z, const timelib_error_container *error) /* {{{ */ { int i; zval element; @@ -3498,7 +3494,7 @@ PHP_METHOD(DateTimeImmutable, sub) } /* }}} */ -static void set_timezone_from_timelib_time(php_timezone_obj *tzobj, timelib_time *t) +static void set_timezone_from_timelib_time(php_timezone_obj *tzobj, const timelib_time *t) { /* Free abbreviation if already set */ if (tzobj->initialized && tzobj->type == TIMELIB_ZONETYPE_ABBR) { @@ -4057,7 +4053,7 @@ PHP_METHOD(DateTimeZone, __construct) } /* }}} */ -static bool php_date_timezone_initialize_from_hash(zval **return_value, php_timezone_obj **tzobj, HashTable *myht) /* {{{ */ +static bool php_date_timezone_initialize_from_hash(zval **return_value, php_timezone_obj **tzobj, const HashTable *myht) /* {{{ */ { zval *z_timezone_type; @@ -4087,15 +4083,12 @@ static bool php_date_timezone_initialize_from_hash(zval **return_value, php_time PHP_METHOD(DateTimeZone, __set_state) { php_timezone_obj *tzobj; - zval *array; HashTable *myht; ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_ARRAY(array) + Z_PARAM_ARRAY_HT(myht) ZEND_PARSE_PARAMETERS_END(); - myht = Z_ARRVAL_P(array); - php_date_instantiate(date_ce_timezone, return_value); tzobj = Z_PHPTIMEZONE_P(return_value); if (!php_date_timezone_initialize_from_hash(&return_value, &tzobj, myht)) { @@ -4110,7 +4103,7 @@ PHP_METHOD(DateTimeZone, __wakeup) { zval *object = ZEND_THIS; php_timezone_obj *tzobj; - HashTable *myht; + const HashTable *myht; ZEND_PARSE_PARAMETERS_NONE(); @@ -4145,7 +4138,7 @@ PHP_METHOD(DateTimeZone, __serialize) } /* }}} */ -static bool date_timezone_is_internal_property(zend_string *name) +static bool date_timezone_is_internal_property(const zend_string *name) { if ( zend_string_equals_literal(name, "timezone_type") || @@ -4156,7 +4149,7 @@ static bool date_timezone_is_internal_property(zend_string *name) return 0; } -static void restore_custom_datetimezone_properties(zval *object, HashTable *myht) +static void restore_custom_datetimezone_properties(zval *object, const HashTable *myht) { zend_string *prop_name; zval *prop_val; @@ -4174,15 +4167,13 @@ PHP_METHOD(DateTimeZone, __unserialize) { zval *object = ZEND_THIS; php_timezone_obj *tzobj; - zval *array; HashTable *myht; ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_ARRAY(array) + Z_PARAM_ARRAY_HT(myht) ZEND_PARSE_PARAMETERS_END(); tzobj = Z_PHPTIMEZONE_P(object); - myht = Z_ARRVAL_P(array); if (!php_date_timezone_initialize_from_hash(&object, &tzobj, myht)) { zend_throw_error(NULL, "Invalid serialization data for DateTimeZone object"); @@ -4422,7 +4413,7 @@ PHP_FUNCTION(timezone_location_get) } /* }}} */ -static bool date_interval_initialize(timelib_rel_time **rt, /*const*/ char *format, size_t format_length) /* {{{ */ +static bool date_interval_initialize(timelib_rel_time **rt, const char *format, size_t format_length) /* {{{ */ { timelib_time *b = NULL, *e = NULL; timelib_rel_time *p = NULL; @@ -4607,10 +4598,10 @@ PHP_METHOD(DateInterval, __construct) } /* }}} */ -static void php_date_interval_initialize_from_hash(zval **return_value, php_interval_obj **intobj, HashTable *myht) /* {{{ */ +static void php_date_interval_initialize_from_hash(zval **return_value, php_interval_obj **intobj, const HashTable *myht) /* {{{ */ { /* If we have a date_string, use that instead */ - zval *date_str = zend_hash_str_find(myht, "date_string", strlen("date_string")); + const zval *date_str = zend_hash_str_find(myht, "date_string", strlen("date_string")); if (date_str && Z_TYPE_P(date_str) == IS_STRING) { timelib_time *time; timelib_error_container *err = NULL; @@ -4708,7 +4699,7 @@ static void php_date_interval_initialize_from_hash(zval **return_value, php_inte PHP_DATE_INTERVAL_READ_PROPERTY("i", i, timelib_sll, -1) PHP_DATE_INTERVAL_READ_PROPERTY("s", s, timelib_sll, -1) { - zval *z_arg = zend_hash_str_find(myht, "f", sizeof("f") - 1); + const zval *z_arg = zend_hash_str_find(myht, "f", sizeof("f") - 1); if (z_arg) { (*intobj)->diff->us = zend_dval_to_lval(zval_get_double(z_arg) * 1000000.0); } @@ -4723,7 +4714,7 @@ static void php_date_interval_initialize_from_hash(zval **return_value, php_inte PHP_DATE_INTERVAL_READ_PROPERTY("have_weekday_relative", have_weekday_relative, unsigned int, 0); PHP_DATE_INTERVAL_READ_PROPERTY("have_special_relative", have_special_relative, unsigned int, 0); { - zval *z_arg = zend_hash_str_find(myht, "civil_or_wall", sizeof("civil_or_wall") - 1); + const zval *z_arg = zend_hash_str_find(myht, "civil_or_wall", sizeof("civil_or_wall") - 1); (*intobj)->civil_or_wall = PHP_DATE_CIVIL; if (z_arg) { zend_long val = zval_get_long(z_arg); @@ -4738,15 +4729,12 @@ static void php_date_interval_initialize_from_hash(zval **return_value, php_inte PHP_METHOD(DateInterval, __set_state) { php_interval_obj *intobj; - zval *array; HashTable *myht; ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_ARRAY(array) + Z_PARAM_ARRAY_HT(myht) ZEND_PARSE_PARAMETERS_END(); - myht = Z_ARRVAL_P(array); - php_date_instantiate(date_ce_interval, return_value); intobj = Z_PHPINTERVAL_P(return_value); php_date_interval_initialize_from_hash(&return_value, &intobj, myht); @@ -4773,7 +4761,7 @@ PHP_METHOD(DateInterval, __serialize) } /* }}} */ -static bool date_interval_is_internal_property(zend_string *name) +static bool date_interval_is_internal_property(const zend_string *name) { if ( zend_string_equals_literal(name, "date_string") || @@ -4793,7 +4781,7 @@ static bool date_interval_is_internal_property(zend_string *name) return 0; } -static void restore_custom_dateinterval_properties(zval *object, HashTable *myht) +static void restore_custom_dateinterval_properties(zval *object, const HashTable *myht) { zend_string *prop_name; zval *prop_val; @@ -4812,15 +4800,13 @@ PHP_METHOD(DateInterval, __unserialize) { zval *object = ZEND_THIS; php_interval_obj *intervalobj; - zval *array; HashTable *myht; ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_ARRAY(array) + Z_PARAM_ARRAY_HT(myht) ZEND_PARSE_PARAMETERS_END(); intervalobj = Z_PHPINTERVAL_P(object); - myht = Z_ARRVAL_P(array); php_date_interval_initialize_from_hash(&object, &intervalobj, myht); restore_custom_dateinterval_properties(object, myht); @@ -4832,7 +4818,7 @@ PHP_METHOD(DateInterval, __wakeup) { zval *object = ZEND_THIS; php_interval_obj *intobj; - HashTable *myht; + const HashTable *myht; ZEND_PARSE_PARAMETERS_NONE(); @@ -4924,7 +4910,7 @@ PHP_METHOD(DateInterval, createFromDateString) /* }}} */ /* {{{ date_interval_format - */ -static zend_string *date_interval_format(char *format, size_t format_len, timelib_rel_time *t) +static zend_string *date_interval_format(const char *format, size_t format_len, timelib_rel_time *t) { smart_str string = {0}; size_t i; @@ -4998,7 +4984,7 @@ PHP_FUNCTION(date_interval_format) { zval *object; php_interval_obj *diobj; - char *format; + const char *format; size_t format_len; if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os", &object, date_ce_interval, &format, &format_len) == FAILURE) { @@ -5011,7 +4997,7 @@ PHP_FUNCTION(date_interval_format) } /* }}} */ -static bool date_period_initialize(timelib_time **st, timelib_time **et, timelib_rel_time **d, zend_long *recurrences, /*const*/ char *format, size_t format_length) /* {{{ */ +static bool date_period_initialize(timelib_time **st, timelib_time **et, timelib_rel_time **d, zend_long *recurrences, const char *format, size_t format_length) /* {{{ */ { timelib_time *b = NULL, *e = NULL; timelib_rel_time *p = NULL; @@ -5044,7 +5030,7 @@ static bool date_period_initialize(timelib_time **st, timelib_time **et, timelib return retval; } /* }}} */ -static bool date_period_init_iso8601_string(php_period_obj *dpobj, zend_class_entry* base_ce, char *isostr, size_t isostr_len, zend_long options, zend_long *recurrences) +static bool date_period_init_iso8601_string(php_period_obj *dpobj, zend_class_entry* base_ce, const char *isostr, size_t isostr_len, zend_long *recurrences) { if (!date_period_initialize(&(dpobj->start), &(dpobj->end), &(dpobj->interval), recurrences, isostr, isostr_len)) { return false; @@ -5130,7 +5116,7 @@ PHP_METHOD(DatePeriod, createFromISO8601String) dpobj->current = NULL; - if (!date_period_init_iso8601_string(dpobj, date_ce_immutable, isostr, isostr_len, options, &recurrences)) { + if (!date_period_init_iso8601_string(dpobj, date_ce_immutable, isostr, isostr_len, &recurrences)) { RETURN_THROWS(); } @@ -5169,7 +5155,7 @@ PHP_METHOD(DatePeriod, __construct) RETURN_THROWS(); } - if (!date_period_init_iso8601_string(dpobj, date_ce_date, isostr, isostr_len, options, &recurrences)) { + if (!date_period_init_iso8601_string(dpobj, date_ce_date, isostr, isostr_len, &recurrences)) { RETURN_THROWS(); } } else { @@ -5305,7 +5291,7 @@ PHP_METHOD(DatePeriod, getIterator) zend_create_internal_iterator_zval(return_value, ZEND_THIS); } -static int check_id_allowed(char *id, zend_long what) /* {{{ */ +static bool check_id_allowed(const char *id, zend_long what) /* {{{ */ { if ((what & PHP_DATE_TIMEZONE_GROUP_AFRICA) && strncasecmp(id, "Africa/", 7) == 0) return 1; if ((what & PHP_DATE_TIMEZONE_GROUP_AMERICA) && strncasecmp(id, "America/", 8) == 0) return 1; @@ -5711,7 +5697,7 @@ static void date_period_object_to_hash(php_period_obj *period_obj, HashTable *pr zend_hash_str_update(props, "include_end_date", sizeof("include_end_date")-1, &zv); } -static bool php_date_period_initialize_from_hash(php_period_obj *period_obj, HashTable *myht) /* {{{ */ +static bool php_date_period_initialize_from_hash(php_period_obj *period_obj, const HashTable *myht) /* {{{ */ { zval *ht_entry; @@ -5835,15 +5821,12 @@ static bool php_date_period_initialize_from_hash(php_period_obj *period_obj, Has PHP_METHOD(DatePeriod, __set_state) { php_period_obj *period_obj; - zval *array; HashTable *myht; ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_ARRAY(array) + Z_PARAM_ARRAY_HT(myht) ZEND_PARSE_PARAMETERS_END(); - myht = Z_ARRVAL_P(array); - object_init_ex(return_value, date_ce_period); period_obj = Z_PHPPERIOD_P(return_value); if (!php_date_period_initialize_from_hash(period_obj, myht)) { @@ -5877,7 +5860,7 @@ PHP_METHOD(DatePeriod, __serialize) * Common for date_period_read_property(), date_period_write_property(), and * restore_custom_dateperiod_properties functions */ -static bool date_period_is_internal_property(zend_string *name) +static bool date_period_is_internal_property(const zend_string *name) { if ( zend_string_equals_literal(name, "start") || @@ -5894,7 +5877,7 @@ static bool date_period_is_internal_property(zend_string *name) } /* }}} */ -static void restore_custom_dateperiod_properties(zval *object, HashTable *myht) +static void restore_custom_dateperiod_properties(zval *object, const HashTable *myht) { zend_string *prop_name; zval *prop_val; @@ -5912,15 +5895,13 @@ PHP_METHOD(DatePeriod, __unserialize) { zval *object = ZEND_THIS; php_period_obj *period_obj; - zval *array; HashTable *myht; ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_ARRAY(array) + Z_PARAM_ARRAY_HT(myht) ZEND_PARSE_PARAMETERS_END(); period_obj = Z_PHPPERIOD_P(object); - myht = Z_ARRVAL_P(array); if (!php_date_period_initialize_from_hash(period_obj, myht)) { zend_throw_error(NULL, "Invalid serialization data for DatePeriod object"); @@ -5935,7 +5916,7 @@ PHP_METHOD(DatePeriod, __wakeup) { zval *object = ZEND_THIS; php_period_obj *period_obj; - HashTable *myht; + const HashTable *myht; ZEND_PARSE_PARAMETERS_NONE(); diff --git a/ext/date/php_date.h b/ext/date/php_date.h index f1b7c892001a9..f5f43bc7dfb0f 100644 --- a/ext/date/php_date.h +++ b/ext/date/php_date.h @@ -89,9 +89,9 @@ static inline php_timezone_obj *php_timezone_obj_from_obj(zend_object *obj) { struct _php_interval_obj { timelib_rel_time *diff; int civil_or_wall; + bool initialized; bool from_string; zend_string *date_string; - bool initialized; zend_object std; }; @@ -140,7 +140,7 @@ PHPAPI int php_idate(char format, time_t ts, bool localtime); PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, bool gm); PHPAPI zend_string *php_format_date(const char *format, size_t format_len, time_t ts, bool localtime); -PHPAPI zend_string *php_format_date_obj(const char *format, size_t format_len, php_date_obj *date_obj); +PHPAPI zend_string *php_format_date_obj(const char *format, size_t format_len, const php_date_obj *date_obj); /* Mechanism to set new TZ database */ PHPAPI void php_date_set_tzdb(timelib_tzdb *tzdb);