From: Christoph M. Becker Date: Mon, 30 Mar 2020 07:18:20 +0000 (+0200) Subject: Merge branch 'PHP-7.4' X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6b6f0d63f3d4f3bfa51ed8b1358dc013acda45cf;p=php Merge branch 'PHP-7.4' * PHP-7.4: Fix #74940: DateTimeZone loose comparison always true --- 6b6f0d63f3d4f3bfa51ed8b1358dc013acda45cf diff --cc ext/date/php_date.c index edccb07c40,02068b44cc..00d7892a6a --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@@ -335,13 -673,15 +335,15 @@@ static HashTable *date_object_get_debug static void php_timezone_to_string(php_timezone_obj *tzobj, zval *zv); static int date_interval_compare_objects(zval *o1, zval *o2); -static zval *date_interval_read_property(zval *object, zval *member, int type, void **cache_slot, zval *rv); -static zval *date_interval_write_property(zval *object, zval *member, zval *value, void **cache_slot); -static zval *date_interval_get_property_ptr_ptr(zval *object, zval *member, int type, void **cache_slot); -static zval *date_period_read_property(zval *object, zval *member, int type, void **cache_slot, zval *rv); -static zval *date_period_write_property(zval *object, zval *member, zval *value, void **cache_slot); -static zval *date_period_get_property_ptr_ptr(zval *object, zval *member, int type, void **cache_slot); +static zval *date_interval_read_property(zend_object *object, zend_string *member, int type, void **cache_slot, zval *rv); +static zval *date_interval_write_property(zend_object *object, zend_string *member, zval *value, void **cache_slot); +static zval *date_interval_get_property_ptr_ptr(zend_object *object, zend_string *member, int type, void **cache_slot); +static zval *date_period_read_property(zend_object *object, zend_string *name, int type, void **cache_slot, zval *rv); +static zval *date_period_write_property(zend_object *object, zend_string *name, zval *value, void **cache_slot); +static zval *date_period_get_property_ptr_ptr(zend_object *object, zend_string *name, int type, void **cache_slot); + static int date_object_compare_timezone(zval *tz1, zval *tz2); + /* {{{ Module struct */ zend_module_entry date_module_entry = { STANDARD_MODULE_HEADER_EX, @@@ -1794,6 -2157,7 +1796,7 @@@ static void date_register_classes(void date_object_handlers_timezone.get_properties_for = date_object_get_properties_for_timezone; date_object_handlers_timezone.get_gc = date_object_get_gc_timezone; date_object_handlers_timezone.get_debug_info = date_object_get_debug_info_timezone; ++ date_object_handlers_timezone.compare = date_object_compare_timezone; #define REGISTER_TIMEZONE_CLASS_CONST_STRING(const_name, value) \ zend_declare_class_constant_long(date_ce_timezone, const_name, sizeof(const_name)-1, value); @@@ -2024,6 -2383,31 +2027,33 @@@ static zend_object *date_object_clone_t return &new_obj->std; } /* }}} */ + static int date_object_compare_timezone(zval *tz1, zval *tz2) /* {{{ */ + { + php_timezone_obj *o1, *o2; + ++ ZEND_COMPARE_OBJECTS_FALLBACK(tz1, tz2); ++ + o1 = Z_PHPTIMEZONE_P(tz1); + o2 = Z_PHPTIMEZONE_P(tz2); + + ZEND_ASSERT(o1->initialized && o2->initialized); + + if (o1->type != o2->type) { + php_error_docref(NULL, E_WARNING, "Trying to compare different kinds of DateTimeZone objects"); + return 1; + } + + switch (o1->type) { + case TIMELIB_ZONETYPE_OFFSET: + return o1->tzi.utc_offset == o2->tzi.utc_offset ? 0 : 1; + case TIMELIB_ZONETYPE_ABBR: + return strcmp(o1->tzi.z.abbr, o2->tzi.z.abbr) ? 1 : 0; + case TIMELIB_ZONETYPE_ID: + return strcmp(o1->tzi.tz->name, o2->tzi.tz->name) ? 1 : 0; + EMPTY_SWITCH_DEFAULT_CASE(); + } + } /* }}} */ + static void php_timezone_to_string(php_timezone_obj *tzobj, zval *zv) { switch (tzobj->type) {