php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #53437
Patch date_patch_var4.patch revision 2013-03-14 15:21 UTC by ab@php.net
Patch date_patch_var3.patch revision 2013-03-13 08:53 UTC by ab@php.net
Patch glopes_date_5.3.patch revision 2013-03-06 18:50 UTC by ab@php.net
revision 2013-03-05 11:19 UTC by ab@php.net
Patch glopes_date_5.4.patch revision 2013-03-05 11:20 UTC by ab@php.net

Patch date_patch_var4.patch for Date/time related Bug #53437

Patch version 2013-03-14 15:21 UTC

Return to Bug #53437 | Download this patch
This patch renders other patches obsolete

Obsolete patches:

Patch Revisions:

Developer: ab@php.net

diff --git a/ext/date/php_date.c b/ext/date/php_date.c
index 7195857..3942a66 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -39,6 +39,20 @@ static __inline __int64_t php_date_llabs( __int64_t i ) { return i >= 0 ? i : -i
 static inline long long php_date_llabs( long long i ) { return i >= 0 ? i : -i; }
 #endif
 
+#ifdef PHP_WIN32
+#define DATE_I64_BUF_LEN 65
+# define DATE_I64A(i, s, len) _i64toa_s(i, s, len, 10)
+# define DATE_A64I(i, s) i = _atoi64(s)
+#else
+#define DATE_I64_BUF_LEN 65
+# define DATE_I64A(i, s, len) \
+	do { \
+		int st = snprintf(s, len, "%lld", i); \
+		s[st] = '\0'; \
+	} while (0);
+# define DATE_A64I(i, s) i = atoll(s)
+#endif
+
 /* {{{ arginfo */
 ZEND_BEGIN_ARG_INFO_EX(arginfo_date, 0, 0, 1)
 	ZEND_ARG_INFO(0, format)
@@ -488,6 +502,8 @@ const zend_function_entry date_funcs_interval[] = {
 
 const zend_function_entry date_funcs_period[] = {
 	PHP_ME(DatePeriod,                __construct,                 arginfo_date_period_construct, ZEND_ACC_CTOR|ZEND_ACC_PUBLIC)
+	PHP_ME(DatePeriod,                __wakeup,                    NULL, ZEND_ACC_PUBLIC)
+	PHP_ME(DatePeriod,                __set_state,                 NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
 	PHP_FE_END
 };
 
@@ -594,9 +610,13 @@ static HashTable *date_object_get_gc(zval *object, zval ***table, int *n TSRMLS_
 static HashTable *date_object_get_properties(zval *object TSRMLS_DC);
 static HashTable *date_object_get_gc_interval(zval *object, zval ***table, int *n TSRMLS_DC);
 static HashTable *date_object_get_properties_interval(zval *object TSRMLS_DC);
+static HashTable *date_object_get_gc_period(zval *object, zval ***table, int *n TSRMLS_DC);
+static HashTable *date_object_get_properties_period(zval *object TSRMLS_DC);
 
 zval *date_interval_read_property(zval *object, zval *member, int type, const zend_literal *key TSRMLS_DC);
 void date_interval_write_property(zval *object, zval *member, zval *value, const zend_literal *key TSRMLS_DC);
+static zval *date_period_read_property(zval *object, zval *member, int type, const zend_literal *key TSRMLS_DC);
+static void date_period_write_property(zval *object, zval *member, zval *value, const zend_literal *key TSRMLS_DC);
 
 /* {{{ Module struct */
 zend_module_entry date_module_entry = {
@@ -2013,6 +2033,11 @@ static void date_register_classes(TSRMLS_D)
 	zend_class_implements(date_ce_period TSRMLS_CC, 1, zend_ce_traversable);
 	memcpy(&date_object_handlers_period, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
 	date_object_handlers_period.clone_obj = date_object_clone_period;
+	date_object_handlers_period.get_properties = date_object_get_properties_period;
+	date_object_handlers_period.get_property_ptr_ptr = NULL;
+	date_object_handlers_period.get_gc = date_object_get_gc_period;
+	date_object_handlers_period.read_property = date_period_read_property;
+	date_object_handlers_period.write_property = date_period_write_property;
 
 #define REGISTER_PERIOD_CLASS_CONST_STRING(const_name, value) \
 	zend_declare_class_constant_long(date_ce_period, const_name, sizeof(const_name)-1, value TSRMLS_CC);
@@ -2125,7 +2150,7 @@ static HashTable *date_object_get_properties(zval *object TSRMLS_DC)
 
 	props = zend_std_get_properties(object TSRMLS_CC);
 
-	if (!dateobj->time) {
+	if (!dateobj->time || GC_G(gc_active)) {
 		return props;
 	}
 
@@ -2272,6 +2297,7 @@ static HashTable *date_object_get_properties_interval(zval *object TSRMLS_DC)
 	HashTable *props;
 	zval *zv;
 	php_interval_obj     *intervalobj;
+	char i64_buf[DATE_I64_BUF_LEN];
 
 
 	intervalobj = (php_interval_obj *) zend_object_store_get_object(object TSRMLS_CC);
@@ -2282,25 +2308,38 @@ static HashTable *date_object_get_properties_interval(zval *object TSRMLS_DC)
 		return props;
 	}
 
+#define PHP_DATE_INTERVAL_ADD_PROPERTY_I64(n, f) \
+	MAKE_STD_ZVAL(zv); \
+	DATE_I64A(intervalobj->diff->f, i64_buf, DATE_I64_BUF_LEN); \
+	ZVAL_STRING(zv, i64_buf, 1); \
+	zend_hash_update(props, n, strlen(n) + 1, &zv, sizeof(zval), NULL);
+
 #define PHP_DATE_INTERVAL_ADD_PROPERTY(n,f) \
 	MAKE_STD_ZVAL(zv); \
 	ZVAL_LONG(zv, intervalobj->diff->f); \
 	zend_hash_update(props, n, strlen(n) + 1, &zv, sizeof(zval), NULL);
 
-	PHP_DATE_INTERVAL_ADD_PROPERTY("y", y);
-	PHP_DATE_INTERVAL_ADD_PROPERTY("m", m);
-	PHP_DATE_INTERVAL_ADD_PROPERTY("d", d);
-	PHP_DATE_INTERVAL_ADD_PROPERTY("h", h);
-	PHP_DATE_INTERVAL_ADD_PROPERTY("i", i);
-	PHP_DATE_INTERVAL_ADD_PROPERTY("s", s);
+	PHP_DATE_INTERVAL_ADD_PROPERTY_I64("y", y);
+	PHP_DATE_INTERVAL_ADD_PROPERTY_I64("m", m);
+	PHP_DATE_INTERVAL_ADD_PROPERTY_I64("d", d);
+	PHP_DATE_INTERVAL_ADD_PROPERTY_I64("h", h);
+	PHP_DATE_INTERVAL_ADD_PROPERTY_I64("i", i);
+	PHP_DATE_INTERVAL_ADD_PROPERTY_I64("s", s);
+	PHP_DATE_INTERVAL_ADD_PROPERTY("weekday", weekday);
+	PHP_DATE_INTERVAL_ADD_PROPERTY("weekday_behavior", weekday_behavior);
+	PHP_DATE_INTERVAL_ADD_PROPERTY("first_last_day_of", first_last_day_of);
 	PHP_DATE_INTERVAL_ADD_PROPERTY("invert", invert);
 	if (intervalobj->diff->days != -99999) {
-		PHP_DATE_INTERVAL_ADD_PROPERTY("days", days);
+		PHP_DATE_INTERVAL_ADD_PROPERTY_I64("days", days);
 	} else {
 		MAKE_STD_ZVAL(zv);
 		ZVAL_FALSE(zv);
 		zend_hash_update(props, "days", 5, &zv, sizeof(zval), NULL);
 	}
+	PHP_DATE_INTERVAL_ADD_PROPERTY("special_type", special.type);
+	PHP_DATE_INTERVAL_ADD_PROPERTY_I64("special_amount", special.amount);
+	PHP_DATE_INTERVAL_ADD_PROPERTY("have_weekday_relative", have_weekday_relative);
+	PHP_DATE_INTERVAL_ADD_PROPERTY("have_special_relative", have_special_relative);
 
 	return props;
 }
@@ -2402,6 +2441,7 @@ PHPAPI zval *php_date_instantiate(zend_class_entry *pce, zval *object TSRMLS_DC)
 	object_init_ex(object, pce);
 	Z_SET_REFCOUNT_P(object, 1);
 	Z_UNSET_ISREF_P(object);
+
 	return object;
 }
 
@@ -3952,30 +3992,48 @@ PHP_METHOD(DateInterval, __construct)
 }
 /* }}} */
 
-static long php_date_long_from_hash_element(HashTable *myht, char *element, size_t size)
-{
-	zval            **z_arg = NULL;
-
-	if (zend_hash_find(myht, element, size + 1, (void**) &z_arg) == SUCCESS) {
-		convert_to_long(*z_arg);
-		return Z_LVAL_PP(z_arg);
-	} else {
-		return -1;
-	}
-}
 
 static int php_date_interval_initialize_from_hash(zval **return_value, php_interval_obj **intobj, HashTable *myht TSRMLS_DC)
 {
 	(*intobj)->diff = timelib_rel_time_ctor();
 
-	(*intobj)->diff->y = php_date_long_from_hash_element(myht, "y", 1);
-	(*intobj)->diff->m = php_date_long_from_hash_element(myht, "m", 1);
-	(*intobj)->diff->d = php_date_long_from_hash_element(myht, "d", 1);
-	(*intobj)->diff->h = php_date_long_from_hash_element(myht, "h", 1);
-	(*intobj)->diff->i = php_date_long_from_hash_element(myht, "i", 1);
-	(*intobj)->diff->s = php_date_long_from_hash_element(myht, "s", 1);
-	(*intobj)->diff->invert = php_date_long_from_hash_element(myht, "invert", 6);
-	(*intobj)->diff->days = php_date_long_from_hash_element(myht, "days", 4);
+#define PHP_DATE_INTERVAL_READ_PROPERTY(element, member, itype) \
+	do { \
+		zval **z_arg = NULL; \
+		if (zend_hash_find(myht, element, strlen(element) + 1, (void**) &z_arg) == SUCCESS) { \
+			convert_to_long(*z_arg); \
+			(*intobj)->diff->member = (itype)Z_LVAL_PP(z_arg); \
+		} else { \
+			(*intobj)->diff->member = (itype)-1; \
+		} \
+	} while (0);
+
+#define PHP_DATE_INTERVAL_READ_PROPERTY_I64(element, member) \
+	do { \
+		zval **z_arg = NULL; \
+		if (zend_hash_find(myht, element, strlen(element) + 1, (void**) &z_arg) == SUCCESS) { \
+			convert_to_string(*z_arg); \
+			DATE_A64I((*intobj)->diff->member, Z_STRVAL_PP(z_arg)); \
+		} else { \
+			(*intobj)->diff->member = -1LL; \
+		} \
+	} while (0);
+
+	PHP_DATE_INTERVAL_READ_PROPERTY_I64("y", y)
+	PHP_DATE_INTERVAL_READ_PROPERTY_I64("m", m)
+	PHP_DATE_INTERVAL_READ_PROPERTY_I64("d", d)
+	PHP_DATE_INTERVAL_READ_PROPERTY_I64("h", h)
+	PHP_DATE_INTERVAL_READ_PROPERTY_I64("i", i)
+	PHP_DATE_INTERVAL_READ_PROPERTY_I64("s", s)
+	PHP_DATE_INTERVAL_READ_PROPERTY("weekday", weekday, int)
+	PHP_DATE_INTERVAL_READ_PROPERTY("weekday_behavior", weekday_behavior, int)
+	PHP_DATE_INTERVAL_READ_PROPERTY("first_last_day_of", first_last_day_of, int)
+	PHP_DATE_INTERVAL_READ_PROPERTY("invert", invert, int);
+	PHP_DATE_INTERVAL_READ_PROPERTY_I64("days", days);
+	PHP_DATE_INTERVAL_READ_PROPERTY("special_type", special.type, unsigned int);
+	PHP_DATE_INTERVAL_READ_PROPERTY_I64("special_amount", special.amount);
+	PHP_DATE_INTERVAL_READ_PROPERTY("have_weekday_relative", have_weekday_relative, unsigned int);
+	PHP_DATE_INTERVAL_READ_PROPERTY("have_special_relative", have_special_relative, unsigned int);
 	(*intobj)->initialized = 1;
 
 	return 0;
@@ -4581,6 +4639,230 @@ PHP_FUNCTION(date_sun_info)
 	timelib_time_dtor(t2);
 }
 /* }}} */
+
+static HashTable *date_object_get_gc_period(zval *object, zval ***table, int *n TSRMLS_DC)
+{
+	*table = NULL;
+	*n = 0;
+	return zend_std_get_properties(object TSRMLS_CC);
+}
+
+static HashTable *date_object_get_properties_period(zval *object TSRMLS_DC)
+{
+	HashTable		*props;
+	zval			*zv;
+	php_period_obj	*period_obj;
+
+	period_obj = zend_object_store_get_object(object TSRMLS_CC);
+
+	props = zend_std_get_properties(object TSRMLS_CC);
+
+	if (!period_obj->start || GC_G(gc_active)) {
+		return props;
+	}
+
+	MAKE_STD_ZVAL(zv);
+	if (period_obj->start) {
+		php_date_obj *date_obj;
+		object_init_ex(zv, date_ce_date);
+		date_obj = zend_object_store_get_object(zv TSRMLS_CC);
+		date_obj->time = timelib_time_clone(period_obj->start);
+	} else {
+		ZVAL_NULL(zv);
+	}
+	zend_hash_update(props, "start", sizeof("start"), &zv, sizeof(zv), NULL);
+
+	MAKE_STD_ZVAL(zv);
+	if (period_obj->current) {
+		php_date_obj *date_obj;
+		object_init_ex(zv, date_ce_date);
+		date_obj = zend_object_store_get_object(zv TSRMLS_CC);
+		date_obj->time = timelib_time_clone(period_obj->current);
+	} else {
+		ZVAL_NULL(zv);
+	}
+	zend_hash_update(props, "current", sizeof("current"), &zv, sizeof(zv), NULL);
+
+	MAKE_STD_ZVAL(zv);
+	if (period_obj->end) {
+		php_date_obj *date_obj;
+		object_init_ex(zv, date_ce_date);
+		date_obj = zend_object_store_get_object(zv TSRMLS_CC);
+		date_obj->time = timelib_time_clone(period_obj->end);
+	} else {
+		ZVAL_NULL(zv);
+	}
+	zend_hash_update(props, "end", sizeof("end"), &zv, sizeof(zv), NULL);
+
+	MAKE_STD_ZVAL(zv);
+	if (period_obj->interval) {
+		php_interval_obj *interval_obj;
+		object_init_ex(zv, date_ce_interval);
+		interval_obj = zend_object_store_get_object(zv TSRMLS_CC);
+		interval_obj->diff = timelib_rel_time_clone(period_obj->interval);
+		interval_obj->initialized = 1;
+	} else {
+		ZVAL_NULL(zv);
+	}
+	zend_hash_update(props, "interval", sizeof("interval"), &zv, sizeof(zv), NULL);
+	
+	/* converted to larger type (int->long); must check when unserializing */
+	MAKE_STD_ZVAL(zv);
+	ZVAL_LONG(zv, (long) period_obj->recurrences);
+	zend_hash_update(props, "recurrences", sizeof("recurrences"), &zv, sizeof(zv), NULL);
+
+	MAKE_STD_ZVAL(zv);
+	ZVAL_BOOL(zv, period_obj->include_start_date);
+	zend_hash_update(props, "include_start_date", sizeof("include_start_date"), &zv, sizeof(zv), NULL);
+
+	return props;
+}
+
+static int php_date_period_initialize_from_hash(php_period_obj *period_obj, HashTable *myht TSRMLS_DC)
+{
+	zval **ht_entry;
+
+	/* this function does no rollback on error */
+
+	if (zend_hash_find(myht, "start", sizeof("start"), (void**) &ht_entry) == SUCCESS) {
+		if (Z_TYPE_PP(ht_entry) == IS_OBJECT && Z_OBJCE_PP(ht_entry) == date_ce_date) {
+			php_date_obj *date_obj;
+			date_obj = zend_object_store_get_object(*ht_entry TSRMLS_CC);
+			period_obj->start = timelib_time_clone(date_obj->time);
+			period_obj->start_ce = Z_OBJCE_PP(ht_entry);
+		} else if (Z_TYPE_PP(ht_entry) != IS_NULL) {
+			return 0;
+		}
+	} else {
+		return 0;
+	}
+
+	if (zend_hash_find(myht, "end", sizeof("end"), (void**) &ht_entry) == SUCCESS) {
+		if (Z_TYPE_PP(ht_entry) == IS_OBJECT && Z_OBJCE_PP(ht_entry) == date_ce_date) {
+			php_date_obj *date_obj;
+			date_obj = zend_object_store_get_object(*ht_entry TSRMLS_CC);
+			period_obj->end = timelib_time_clone(date_obj->time);
+		} else if (Z_TYPE_PP(ht_entry) != IS_NULL) {
+			return 0;
+		}
+	} else {
+		return 0;
+	}
+
+	if (zend_hash_find(myht, "current", sizeof("current"), (void**) &ht_entry) == SUCCESS) {
+		if (Z_TYPE_PP(ht_entry) == IS_OBJECT && Z_OBJCE_PP(ht_entry) == date_ce_date) {
+			php_date_obj *date_obj;
+			date_obj = zend_object_store_get_object(*ht_entry TSRMLS_CC);
+			period_obj->current = timelib_time_clone(date_obj->time);
+		} else if (Z_TYPE_PP(ht_entry) != IS_NULL)  {
+			return 0;
+		}
+	} else {
+		return 0;
+	}
+
+	if (zend_hash_find(myht, "interval", sizeof("interval"), (void**) &ht_entry) == SUCCESS) {
+		if (Z_TYPE_PP(ht_entry) == IS_OBJECT && Z_OBJCE_PP(ht_entry) == date_ce_interval) {
+			php_interval_obj *interval_obj;
+			interval_obj = zend_object_store_get_object(*ht_entry TSRMLS_CC);
+			period_obj->interval = timelib_rel_time_clone(interval_obj->diff);
+		} else { /* interval is required */
+			return 0;
+		}
+	} else {
+		return 0;
+	}
+
+	if (zend_hash_find(myht, "recurrences", sizeof("recurrences"), (void**) &ht_entry) == SUCCESS &&
+			Z_TYPE_PP(ht_entry) == IS_LONG && Z_LVAL_PP(ht_entry) >= 0 && Z_LVAL_PP(ht_entry) <= INT_MAX) {
+		period_obj->recurrences = Z_LVAL_PP(ht_entry);
+	} else {
+		return 0;
+	}
+
+	if (zend_hash_find(myht, "include_start_date", sizeof("include_start_date"), (void**) &ht_entry) == SUCCESS &&
+			Z_TYPE_PP(ht_entry) == IS_BOOL) {
+		period_obj->include_start_date = Z_BVAL_PP(ht_entry);
+	} else {
+		return 0;
+	}
+
+	period_obj->initialized = 1;
+	
+	return 1;
+}
+
+/* {{{ proto DatePeriod::__set_state()
+*/
+PHP_METHOD(DatePeriod, __set_state)
+{
+	php_period_obj   *period_obj;
+	zval             *array;
+	HashTable        *myht;
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &array) == FAILURE) {
+		RETURN_FALSE;
+	}
+
+	myht = Z_ARRVAL_P(array);
+	
+	object_init_ex(return_value, date_ce_period);
+	period_obj = zend_object_store_get_object(return_value TSRMLS_CC);
+	if (!php_date_period_initialize_from_hash(period_obj, myht TSRMLS_CC)) {
+		php_error(E_ERROR, "Invalid serialization data for DatePeriod object");
+	}
+}
+/* }}} */
+
+/* {{{ proto DatePeriod::__wakeup()
+*/
+PHP_METHOD(DatePeriod, __wakeup)
+{
+	zval             *object = getThis();
+	php_period_obj   *period_obj;
+	HashTable        *myht;
+
+	period_obj = zend_object_store_get_object(object TSRMLS_CC);
+
+	myht = Z_OBJPROP_P(object);
+
+	if (!php_date_period_initialize_from_hash(period_obj, myht TSRMLS_CC)) {
+		php_error(E_ERROR, "Invalid serialization data for DatePeriod object");
+	}
+}
+/* }}} */
+
+/* {{{ date_period_read_property */
+static zval *date_period_read_property(zval *object, zval *member, int type, const zend_literal *key TSRMLS_DC)
+{
+	zval *zv;
+	if (type != BP_VAR_IS && type != BP_VAR_R) {
+		php_error_docref(NULL TSRMLS_CC, E_ERROR, "Retrieval of DatePeriod properties for modification is unsupported");
+	}
+
+	Z_OBJPROP_P(object); /* build properties hash table */
+
+	zv = std_object_handlers.read_property(object, member, type, key TSRMLS_CC);
+	if (Z_TYPE_P(zv) == IS_OBJECT && Z_OBJ_HANDLER_P(zv, clone_obj)) {
+		/* defensive copy */
+		zend_object_value zov = Z_OBJ_HANDLER_P(zv, clone_obj)(zv TSRMLS_CC);
+		MAKE_STD_ZVAL(zv);
+		Z_TYPE_P(zv) = IS_OBJECT;
+		Z_OBJVAL_P(zv) = zov;
+	}
+
+	return zv;
+}
+/* }}} */
+
+/* {{{ date_period_write_property */
+static void date_period_write_property(zval *object, zval *member, zval *value, const zend_literal *key TSRMLS_DC)
+{
+	php_error_docref(NULL TSRMLS_CC, E_ERROR, "Writing to DatePeriod properties is unsupported");
+}
+/* }}} */
+
+
 /*
  * Local variables:
  * tab-width: 4
diff --git a/ext/date/php_date.h b/ext/date/php_date.h
index 3af3fa4..efae0a1 100644
--- a/ext/date/php_date.h
+++ b/ext/date/php_date.h
@@ -101,6 +101,8 @@ PHP_FUNCTION(date_interval_format);
 PHP_FUNCTION(date_interval_create_from_date_string);
 
 PHP_METHOD(DatePeriod, __construct);
+PHP_METHOD(DatePeriod, __wakeup);
+PHP_METHOD(DatePeriod, __set_state);
 
 /* Options and Configuration */
 PHP_FUNCTION(date_default_timezone_set);
diff --git a/ext/date/tests/bug45682.phpt b/ext/date/tests/bug45682.phpt
index d8bbfc5..56caa1b 100644
--- a/ext/date/tests/bug45682.phpt
+++ b/ext/date/tests/bug45682.phpt
@@ -12,21 +12,35 @@ $diff = date_diff($date, $other);
 
 var_dump($diff);
 --EXPECT--
-object(DateInterval)#3 (8) {
+object(DateInterval)#3 (15) {
   ["y"]=>
-  int(0)
+  string(1) "0"
   ["m"]=>
-  int(0)
+  string(1) "0"
   ["d"]=>
-  int(3)
+  string(1) "3"
   ["h"]=>
-  int(0)
+  string(1) "0"
   ["i"]=>
-  int(0)
+  string(1) "0"
   ["s"]=>
+  string(1) "0"
+  ["weekday"]=>
+  int(0)
+  ["weekday_behavior"]=>
+  int(0)
+  ["first_last_day_of"]=>
   int(0)
   ["invert"]=>
   int(0)
   ["days"]=>
-  int(3)
+  string(1) "3"
+  ["special_type"]=>
+  int(0)
+  ["special_amount"]=>
+  string(1) "0"
+  ["have_weekday_relative"]=>
+  int(0)
+  ["have_special_relative"]=>
+  int(0)
 }
diff --git a/ext/date/tests/bug48678.phpt b/ext/date/tests/bug48678.phpt
index e2cb724..253cb84 100644
--- a/ext/date/tests/bug48678.phpt
+++ b/ext/date/tests/bug48678.phpt
@@ -15,8 +15,15 @@ DateInterval Object
     [h] => 12
     [i] => 30
     [s] => 5
+    [weekday] => 0
+    [weekday_behavior] => 0
+    [first_last_day_of] => 0
     [invert] => 0
-    [days] =>%s
+    [days] => 
+    [special_type] => 0
+    [special_amount] => 0
+    [have_weekday_relative] => 0
+    [have_special_relative] => 0
 )
 DateInterval Object
 (
@@ -26,6 +33,13 @@ DateInterval Object
     [h] => 12
     [i] => 30
     [s] => 5
+    [weekday] => 0
+    [weekday_behavior] => 0
+    [first_last_day_of] => 0
     [invert] => 0
-    [days] =>%s
+    [days] => 0
+    [special_type] => 0
+    [special_amount] => 0
+    [have_weekday_relative] => 0
+    [have_special_relative] => 0
 )
diff --git a/ext/date/tests/bug49081.phpt b/ext/date/tests/bug49081.phpt
index f4f0290..31f7351 100644
--- a/ext/date/tests/bug49081.phpt
+++ b/ext/date/tests/bug49081.phpt
@@ -17,6 +17,13 @@ DateInterval Object
     [h] => 4
     [i] => 0
     [s] => 0
+    [weekday] => 0
+    [weekday_behavior] => 0
+    [first_last_day_of] => 0
     [invert] => 0
     [days] => 30
+    [special_type] => 0
+    [special_amount] => 0
+    [have_weekday_relative] => 0
+    [have_special_relative] => 0
 )
diff --git a/ext/date/tests/bug49778.phpt b/ext/date/tests/bug49778.phpt
index 67c8e27..ac0244c 100644
--- a/ext/date/tests/bug49778.phpt
+++ b/ext/date/tests/bug49778.phpt
@@ -8,23 +8,37 @@ echo $i->format("%d"), "\n";
 echo $i->format("%a"), "\n";
 ?>
 --EXPECT--
-object(DateInterval)#1 (8) {
+object(DateInterval)#1 (15) {
   ["y"]=>
-  int(0)
+  string(1) "0"
   ["m"]=>
-  int(0)
+  string(1) "0"
   ["d"]=>
-  int(7)
+  string(1) "7"
   ["h"]=>
-  int(0)
+  string(1) "0"
   ["i"]=>
-  int(0)
+  string(1) "0"
   ["s"]=>
+  string(1) "0"
+  ["weekday"]=>
+  int(0)
+  ["weekday_behavior"]=>
+  int(0)
+  ["first_last_day_of"]=>
   int(0)
   ["invert"]=>
   int(0)
   ["days"]=>
   bool(false)
+  ["special_type"]=>
+  int(0)
+  ["special_amount"]=>
+  string(1) "0"
+  ["have_weekday_relative"]=>
+  int(0)
+  ["have_special_relative"]=>
+  int(0)
 }
 7
 (unknown)
diff --git a/ext/date/tests/bug52113.phpt b/ext/date/tests/bug52113.phpt
index a7d9339..30ab8cd 100644
--- a/ext/date/tests/bug52113.phpt
+++ b/ext/date/tests/bug52113.phpt
@@ -32,71 +32,220 @@ var_dump($unser, $p);
 
 ?>
 --EXPECT--
-object(DateInterval)#3 (8) {
+object(DateInterval)#3 (15) {
   ["y"]=>
-  int(0)
+  string(1) "0"
   ["m"]=>
-  int(0)
+  string(1) "0"
   ["d"]=>
-  int(0)
+  string(1) "0"
   ["h"]=>
-  int(4)
+  string(1) "4"
   ["i"]=>
-  int(0)
+  string(1) "0"
   ["s"]=>
+  string(1) "0"
+  ["weekday"]=>
+  int(0)
+  ["weekday_behavior"]=>
+  int(0)
+  ["first_last_day_of"]=>
   int(0)
   ["invert"]=>
   int(0)
   ["days"]=>
+  string(1) "0"
+  ["special_type"]=>
+  int(0)
+  ["special_amount"]=>
+  string(1) "0"
+  ["have_weekday_relative"]=>
+  int(0)
+  ["have_special_relative"]=>
   int(0)
 }
-string(128) "O:12:"DateInterval":8:{s:1:"y";i:0;s:1:"m";i:0;s:1:"d";i:0;s:1:"h";i:4;s:1:"i";i:0;s:1:"s";i:0;s:6:"invert";i:0;s:4:"days";i:0;}"
+string(352) "O:12:"DateInterval":15:{s:1:"y";s:1:"0";s:1:"m";s:1:"0";s:1:"d";s:1:"0";s:1:"h";s:1:"4";s:1:"i";s:1:"0";s:1:"s";s:1:"0";s:7:"weekday";i:0;s:16:"weekday_behavior";i:0;s:17:"first_last_day_of";i:0;s:6:"invert";i:0;s:4:"days";s:1:"0";s:12:"special_type";i:0;s:14:"special_amount";s:1:"0";s:21:"have_weekday_relative";i:0;s:21:"have_special_relative";i:0;}"
 DateInterval::__set_state(array(
-   'y' => 0,
-   'm' => 0,
-   'd' => 0,
-   'h' => 4,
-   'i' => 0,
-   's' => 0,
+   'y' => '0',
+   'm' => '0',
+   'd' => '0',
+   'h' => '4',
+   'i' => '0',
+   's' => '0',
+   'weekday' => 0,
+   'weekday_behavior' => 0,
+   'first_last_day_of' => 0,
    'invert' => 0,
-   'days' => 0,
-))object(DateInterval)#5 (8) {
+   'days' => '0',
+   'special_type' => 0,
+   'special_amount' => '0',
+   'have_weekday_relative' => 0,
+   'have_special_relative' => 0,
+))object(DateInterval)#5 (15) {
   ["y"]=>
-  int(0)
+  string(1) "0"
   ["m"]=>
-  int(0)
+  string(1) "0"
   ["d"]=>
-  int(0)
+  string(1) "0"
   ["h"]=>
-  int(4)
+  string(1) "4"
   ["i"]=>
-  int(0)
+  string(1) "0"
   ["s"]=>
+  string(1) "0"
+  ["weekday"]=>
+  int(0)
+  ["weekday_behavior"]=>
+  int(0)
+  ["first_last_day_of"]=>
   int(0)
   ["invert"]=>
   int(0)
   ["days"]=>
+  string(1) "0"
+  ["special_type"]=>
+  int(0)
+  ["special_amount"]=>
+  string(1) "0"
+  ["have_weekday_relative"]=>
+  int(0)
+  ["have_special_relative"]=>
   int(0)
 }
-object(DatePeriod)#6 (0) {
+object(DatePeriod)#6 (6) {
+  ["start"]=>
+  object(DateTime)#4 (3) {
+    ["date"]=>
+    string(19) "2003-01-02 08:00:00"
+    ["timezone_type"]=>
+    int(3)
+    ["timezone"]=>
+    string(3) "UTC"
+  }
+  ["current"]=>
+  NULL
+  ["end"]=>
+  NULL
+  ["interval"]=>
+  object(DateInterval)#7 (15) {
+    ["y"]=>
+    string(1) "0"
+    ["m"]=>
+    string(1) "0"
+    ["d"]=>
+    string(1) "0"
+    ["h"]=>
+    string(1) "4"
+    ["i"]=>
+    string(1) "0"
+    ["s"]=>
+    string(1) "0"
+    ["weekday"]=>
+    int(0)
+    ["weekday_behavior"]=>
+    int(0)
+    ["first_last_day_of"]=>
+    int(0)
+    ["invert"]=>
+    int(0)
+    ["days"]=>
+    string(1) "0"
+    ["special_type"]=>
+    int(0)
+    ["special_amount"]=>
+    string(1) "0"
+    ["have_weekday_relative"]=>
+    int(0)
+    ["have_special_relative"]=>
+    int(0)
+  }
+  ["recurrences"]=>
+  int(3)
+  ["include_start_date"]=>
+  bool(true)
 }
-object(DateInterval)#4 (8) {
+object(DateInterval)#8 (15) {
   ["y"]=>
-  int(7)
+  string(1) "7"
   ["m"]=>
-  int(6)
+  string(1) "6"
   ["d"]=>
-  int(5)
+  string(1) "5"
   ["h"]=>
-  int(4)
+  string(1) "4"
   ["i"]=>
-  int(3)
+  string(1) "3"
   ["s"]=>
-  int(2)
+  string(1) "2"
+  ["weekday"]=>
+  int(-1)
+  ["weekday_behavior"]=>
+  int(-1)
+  ["first_last_day_of"]=>
+  int(-1)
   ["invert"]=>
   int(1)
   ["days"]=>
-  int(2400)
+  string(4) "2400"
+  ["special_type"]=>
+  int(-1)
+  ["special_amount"]=>
+  string(2) "-1"
+  ["have_weekday_relative"]=>
+  int(-1)
+  ["have_special_relative"]=>
+  int(-1)
 }
-object(DatePeriod)#7 (0) {
+object(DatePeriod)#9 (6) {
+  ["start"]=>
+  object(DateTime)#6 (3) {
+    ["date"]=>
+    string(19) "2003-01-02 08:00:00"
+    ["timezone_type"]=>
+    int(3)
+    ["timezone"]=>
+    string(3) "UTC"
+  }
+  ["current"]=>
+  NULL
+  ["end"]=>
+  NULL
+  ["interval"]=>
+  object(DateInterval)#7 (15) {
+    ["y"]=>
+    string(1) "0"
+    ["m"]=>
+    string(1) "0"
+    ["d"]=>
+    string(1) "0"
+    ["h"]=>
+    string(1) "4"
+    ["i"]=>
+    string(1) "0"
+    ["s"]=>
+    string(1) "0"
+    ["weekday"]=>
+    int(0)
+    ["weekday_behavior"]=>
+    int(0)
+    ["first_last_day_of"]=>
+    int(0)
+    ["invert"]=>
+    int(0)
+    ["days"]=>
+    string(1) "0"
+    ["special_type"]=>
+    int(0)
+    ["special_amount"]=>
+    string(1) "0"
+    ["have_weekday_relative"]=>
+    int(0)
+    ["have_special_relative"]=>
+    int(0)
+  }
+  ["recurrences"]=>
+  int(3)
+  ["include_start_date"]=>
+  bool(true)
 }
diff --git a/ext/date/tests/bug52738.phpt b/ext/date/tests/bug52738.phpt
index fc1b602..ea219f7 100644
--- a/ext/date/tests/bug52738.phpt
+++ b/ext/date/tests/bug52738.phpt
@@ -27,6 +27,13 @@ di Object
     [h] => 0
     [i] => 0
     [s] => 0
+    [weekday] => 0
+    [weekday_behavior] => 0
+    [first_last_day_of] => 0
     [invert] => 0
     [days] => 
+    [special_type] => 0
+    [special_amount] => 0
+    [have_weekday_relative] => 0
+    [have_special_relative] => 0
 )
diff --git a/ext/date/tests/bug52808.phpt b/ext/date/tests/bug52808.phpt
index e031ac6..b337f65 100644
--- a/ext/date/tests/bug52808.phpt
+++ b/ext/date/tests/bug52808.phpt
@@ -25,59 +25,101 @@ foreach($intervals as $iv) {
 echo "==DONE==\n";
 ?>
 --EXPECTF--
-object(DateInterval)#%d (8) {
+object(DateInterval)#%d (15) {
   ["y"]=>
-  int(1)
+  string(1) "1"
   ["m"]=>
-  int(2)
+  string(1) "2"
   ["d"]=>
-  int(10)
+  string(2) "10"
   ["h"]=>
-  int(2)
+  string(1) "2"
   ["i"]=>
-  int(30)
+  string(2) "30"
   ["s"]=>
+  string(1) "0"
+  ["weekday"]=>
+  int(0)
+  ["weekday_behavior"]=>
+  int(0)
+  ["first_last_day_of"]=>
   int(0)
   ["invert"]=>
   int(1)
   ["days"]=>
-  int(437)
+  string(3) "437"
+  ["special_type"]=>
+  int(0)
+  ["special_amount"]=>
+  string(1) "0"
+  ["have_weekday_relative"]=>
+  int(0)
+  ["have_special_relative"]=>
+  int(0)
 }
-object(DateInterval)#%d (8) {
+object(DateInterval)#%d (15) {
   ["y"]=>
-  int(0)
+  string(1) "0"
   ["m"]=>
-  int(9)
+  string(1) "9"
   ["d"]=>
-  int(18)
+  string(2) "18"
   ["h"]=>
-  int(21)
+  string(2) "21"
   ["i"]=>
-  int(30)
+  string(2) "30"
   ["s"]=>
+  string(1) "0"
+  ["weekday"]=>
+  int(0)
+  ["weekday_behavior"]=>
+  int(0)
+  ["first_last_day_of"]=>
   int(0)
   ["invert"]=>
   int(0)
   ["days"]=>
-  int(294)
+  string(3) "294"
+  ["special_type"]=>
+  int(0)
+  ["special_amount"]=>
+  string(1) "0"
+  ["have_weekday_relative"]=>
+  int(0)
+  ["have_special_relative"]=>
+  int(0)
 }
-object(DateInterval)#%d (8) {
+object(DateInterval)#%d (15) {
   ["y"]=>
-  int(0)
+  string(1) "0"
   ["m"]=>
-  int(9)
+  string(1) "9"
   ["d"]=>
-  int(18)
+  string(2) "18"
   ["h"]=>
-  int(21)
+  string(2) "21"
   ["i"]=>
-  int(30)
+  string(2) "30"
   ["s"]=>
+  string(1) "0"
+  ["weekday"]=>
+  int(0)
+  ["weekday_behavior"]=>
+  int(0)
+  ["first_last_day_of"]=>
   int(0)
   ["invert"]=>
   int(0)
   ["days"]=>
-  int(294)
+  string(3) "294"
+  ["special_type"]=>
+  int(0)
+  ["special_amount"]=>
+  string(1) "0"
+  ["have_weekday_relative"]=>
+  int(0)
+  ["have_special_relative"]=>
+  int(0)
 }
 DateInterval::__construct(): Failed to parse interval (2007-05-11T15:30:00Z/)
 DateInterval::__construct(): Failed to parse interval (2007-05-11T15:30:00Z)
diff --git a/ext/date/tests/bug53437.phpt b/ext/date/tests/bug53437.phpt
index f089866..aeb756b 100644
--- a/ext/date/tests/bug53437.phpt
+++ b/ext/date/tests/bug53437.phpt
@@ -1,7 +1,5 @@
 --TEST--
-Bug #53437 (Crash when using unserialized DatePeriod instance)
---XFAIL--
-Bug #53437 Not fixed yet
+Bug #53437 (Crash when using unserialized DatePeriod instance), variation 1
 --FILE--
 <?php
 $dp = new DatePeriod(new DateTime('2010-01-01 UTC'), new DateInterval('P1D'), 2);
@@ -20,9 +18,137 @@ $dpu = unserialize($ser); // $dpu has invalid values???
 var_dump($dpu);
 
 echo "Unserialized:\r\n";
-// ???which leads to CRASH:
 foreach($dpu as $dt) {
         echo $dt->format('Y-m-d H:i:s')."\r\n";
 }
 ?>
+==DONE==
 --EXPECT--
+Original:
+2010-01-01 00:00:00
+2010-01-02 00:00:00
+2010-01-03 00:00:00
+
+object(DatePeriod)#1 (6) {
+  ["start"]=>
+  object(DateTime)#2 (3) {
+    ["date"]=>
+    string(19) "2010-01-01 00:00:00"
+    ["timezone_type"]=>
+    int(3)
+    ["timezone"]=>
+    string(3) "UTC"
+  }
+  ["current"]=>
+  object(DateTime)#4 (3) {
+    ["date"]=>
+    string(19) "2010-01-04 00:00:00"
+    ["timezone_type"]=>
+    int(3)
+    ["timezone"]=>
+    string(3) "UTC"
+  }
+  ["end"]=>
+  NULL
+  ["interval"]=>
+  object(DateInterval)#5 (15) {
+    ["y"]=>
+    string(1) "0"
+    ["m"]=>
+    string(1) "0"
+    ["d"]=>
+    string(1) "1"
+    ["h"]=>
+    string(1) "0"
+    ["i"]=>
+    string(1) "0"
+    ["s"]=>
+    string(1) "0"
+    ["weekday"]=>
+    int(0)
+    ["weekday_behavior"]=>
+    int(0)
+    ["first_last_day_of"]=>
+    int(0)
+    ["invert"]=>
+    int(0)
+    ["days"]=>
+    bool(false)
+    ["special_type"]=>
+    int(0)
+    ["special_amount"]=>
+    string(1) "0"
+    ["have_weekday_relative"]=>
+    int(0)
+    ["have_special_relative"]=>
+    int(0)
+  }
+  ["recurrences"]=>
+  int(3)
+  ["include_start_date"]=>
+  bool(true)
+}
+object(DatePeriod)#5 (6) {
+  ["start"]=>
+  object(DateTime)#10 (3) {
+    ["date"]=>
+    string(19) "2010-01-01 00:00:00"
+    ["timezone_type"]=>
+    int(3)
+    ["timezone"]=>
+    string(3) "UTC"
+  }
+  ["current"]=>
+  object(DateTime)#7 (3) {
+    ["date"]=>
+    string(19) "2010-01-04 00:00:00"
+    ["timezone_type"]=>
+    int(3)
+    ["timezone"]=>
+    string(3) "UTC"
+  }
+  ["end"]=>
+  NULL
+  ["interval"]=>
+  object(DateInterval)#8 (15) {
+    ["y"]=>
+    string(1) "0"
+    ["m"]=>
+    string(1) "0"
+    ["d"]=>
+    string(1) "1"
+    ["h"]=>
+    string(1) "0"
+    ["i"]=>
+    string(1) "0"
+    ["s"]=>
+    string(1) "0"
+    ["weekday"]=>
+    int(0)
+    ["weekday_behavior"]=>
+    int(0)
+    ["first_last_day_of"]=>
+    int(0)
+    ["invert"]=>
+    int(0)
+    ["days"]=>
+    string(1) "0"
+    ["special_type"]=>
+    int(0)
+    ["special_amount"]=>
+    string(1) "0"
+    ["have_weekday_relative"]=>
+    int(0)
+    ["have_special_relative"]=>
+    int(0)
+  }
+  ["recurrences"]=>
+  int(3)
+  ["include_start_date"]=>
+  bool(true)
+}
+Unserialized:
+2010-01-01 00:00:00
+2010-01-02 00:00:00
+2010-01-03 00:00:00
+==DONE==
diff --git a/ext/date/tests/date_diff1.phpt b/ext/date/tests/date_diff1.phpt
index cf32fcb..ff20977 100644
--- a/ext/date/tests/date_diff1.phpt
+++ b/ext/date/tests/date_diff1.phpt
@@ -28,21 +28,35 @@ object(DateTime)#2 (3) {
   ["timezone"]=>
   string(3) "EDT"
 }
-object(DateInterval)#3 (8) {
+object(DateInterval)#3 (15) {
   ["y"]=>
-  int(0)
+  string(1) "0"
   ["m"]=>
-  int(1)
+  string(1) "1"
   ["d"]=>
-  int(2)
+  string(1) "2"
   ["h"]=>
-  int(16)
+  string(2) "16"
   ["i"]=>
-  int(19)
+  string(2) "19"
   ["s"]=>
-  int(40)
+  string(2) "40"
+  ["weekday"]=>
+  int(0)
+  ["weekday_behavior"]=>
+  int(0)
+  ["first_last_day_of"]=>
+  int(0)
   ["invert"]=>
   int(0)
   ["days"]=>
-  int(33)
+  string(2) "33"
+  ["special_type"]=>
+  int(0)
+  ["special_amount"]=>
+  string(1) "0"
+  ["have_weekday_relative"]=>
+  int(0)
+  ["have_special_relative"]=>
+  int(0)
 }
--- /dev/null	Thu Mar 14 16:18:24 2013
+++ ext/date/tests/bug53437_var1.phpt	Thu Mar 14 15:16:05 2013
@@ -0,0 +1,13 @@
+--TEST--
+Bug #53437 (Crash when using unserialized DatePeriod instance), variation 2
+--FILE--
+<?php
+$s = 'O:10:"DatePeriod":0:{}';
+
+$dp = unserialize($s);
+
+var_dump($dp);
+?>
+==DONE==
+--EXPECTF--
+Fatal error: Invalid serialization data for DatePeriod object in %sbug53437_var1.php on line %d
--- /dev/null	Thu Mar 14 16:18:38 2013
+++ ext/date/tests/bug53437_var2.phpt	Thu Mar 14 15:15:48 2013
@@ -0,0 +1,80 @@
+--TEST--
+Bug #53437 DateInterval basic serialization
+--FILE--
+<?php
+$di0 = new DateInterval('P2Y4DT6H8M');
+
+$s = serialize($di0);
+
+$di1 = unserialize($s);
+
+var_dump($di0, $di1);
+
+?>
+==DONE==
+--EXPECT--
+object(DateInterval)#1 (15) {
+  ["y"]=>
+  string(1) "2"
+  ["m"]=>
+  string(1) "0"
+  ["d"]=>
+  string(1) "4"
+  ["h"]=>
+  string(1) "6"
+  ["i"]=>
+  string(1) "8"
+  ["s"]=>
+  string(1) "0"
+  ["weekday"]=>
+  int(0)
+  ["weekday_behavior"]=>
+  int(0)
+  ["first_last_day_of"]=>
+  int(0)
+  ["invert"]=>
+  int(0)
+  ["days"]=>
+  bool(false)
+  ["special_type"]=>
+  int(0)
+  ["special_amount"]=>
+  string(1) "0"
+  ["have_weekday_relative"]=>
+  int(0)
+  ["have_special_relative"]=>
+  int(0)
+}
+object(DateInterval)#2 (15) {
+  ["y"]=>
+  string(1) "2"
+  ["m"]=>
+  string(1) "0"
+  ["d"]=>
+  string(1) "4"
+  ["h"]=>
+  string(1) "6"
+  ["i"]=>
+  string(1) "8"
+  ["s"]=>
+  string(1) "0"
+  ["weekday"]=>
+  int(0)
+  ["weekday_behavior"]=>
+  int(0)
+  ["first_last_day_of"]=>
+  int(0)
+  ["invert"]=>
+  int(0)
+  ["days"]=>
+  string(1) "0"
+  ["special_type"]=>
+  int(0)
+  ["special_amount"]=>
+  string(1) "0"
+  ["have_weekday_relative"]=>
+  int(0)
+  ["have_special_relative"]=>
+  int(0)
+}
+==DONE==
--- /dev/null	Thu Mar 14 16:18:44 2013
+++ ext/date/tests/bug53437_var3.phpt	Thu Mar 14 15:58:00 2013
@@ -0,0 +1,45 @@
+--TEST--
+Bug #53437 DateInterval unserialize bad data
+--FILE--
+<?php
+$s = 'O:12:"DateInterval":15:{s:1:"y";s:1:"2";s:1:"m";s:1:"0";s:1:"d";s:1:"4";s:1:"h";s:1:"6";s:1:"i";s:1:"8";s:1:"s";s:1:"0";s:7:"weekday";i:0;s:16:"weekday_behavior";i:0;s:17:"first_last_day_of";i:0;s:6:"invert";i:0;s:4:"days";s:4:"aoeu";s:12:"special_type";i:0;s:14:"special_amount";s:21:"234523452345234532455";s:21:"have_weekday_relative";i:21474836489;s:21:"have_special_relative";i:0;}';
+
+$di = unserialize($s);
+var_dump($di);
+
+?>
+==DONE==
+--EXPECT--
+object(DateInterval)#1 (15) {
+  ["y"]=>
+  string(1) "2"
+  ["m"]=>
+  string(1) "0"
+  ["d"]=>
+  string(1) "4"
+  ["h"]=>
+  string(1) "6"
+  ["i"]=>
+  string(1) "8"
+  ["s"]=>
+  string(1) "0"
+  ["weekday"]=>
+  int(0)
+  ["weekday_behavior"]=>
+  int(0)
+  ["first_last_day_of"]=>
+  int(0)
+  ["invert"]=>
+  int(0)
+  ["days"]=>
+  string(1) "0"
+  ["special_type"]=>
+  int(0)
+  ["special_amount"]=>
+  string(19) "9223372036854775807"
+  ["have_weekday_relative"]=>
+  int(9)
+  ["have_special_relative"]=>
+  int(0)
+}
+==DONE==
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Nov 24 02:01:28 2024 UTC