com php-src: Allow the third arg to DateTime(Immutable)::createFromFormat() to be null.: ext/date/php_date.c ext/date/tests/bug68 669.phpt
| From: | Sara Golemon | Date: | Tue, 30 Dec 2014 21:58:59 +0000 |
| Subject: | com php-src: Allow the third arg to DateTime(Immutable)::createFromFormat() to be null.: ext/date/php_date.c ext/date/tests/bug68 669.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-83947@lists.php.net to get a copy of this message | ||
Commit: 365f428d463502fd8a2c63640b280753df4bf71f
Author: Sara Golemon <pollita@php.net> Tue, 30 Dec 2014 13:54:02 -0800
Committer: Sara Golemon <sgolemon@fb.com> Tue, 30 Dec 2014 13:58:59 -0800
Parents: ef19072af29668a4254785e59984e764f4dd532f
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=365f428d463502fd8a2c63640b280753df4bf71f
Log:
Allow the third arg to DateTime(Immutable)::createFromFormat() to be null.
Permit the same meaning as not passing the arg at all.
Changed paths:
M ext/date/php_date.c
A ext/date/tests/bug68669.phpt
Diff:
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
index f26fea3..5f415fd 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -2628,7 +2628,7 @@ PHP_FUNCTION(date_create_from_format)
size_t time_str_len = 0, format_str_len = 0;
zval datetime_object;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|O", &format_str, &format_str_len,
&time_str, &time_str_len, &timezone_object, date_ce_timezone) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|O!", &format_str,
&format_str_len, &time_str, &time_str_len, &timezone_object, date_ce_timezone) ==
FAILURE) {
RETURN_FALSE;
}
@@ -2651,7 +2651,7 @@ PHP_FUNCTION(date_create_immutable_from_format)
size_t time_str_len = 0, format_str_len = 0;
zval datetime_object;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|O", &format_str, &format_str_len,
&time_str, &time_str_len, &timezone_object, date_ce_timezone) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|O!", &format_str,
&format_str_len, &time_str, &time_str_len, &timezone_object, date_ce_timezone) ==
FAILURE) {
RETURN_FALSE;
}
diff --git a/ext/date/tests/bug68669.phpt b/ext/date/tests/bug68669.phpt
new file mode 100644
index 0000000..8aac1d2
--- /dev/null
+++ b/ext/date/tests/bug68669.phpt
@@ -0,0 +1,25 @@
+--TEST--
+DateTime::createFromFormat() does not allow NULL $timezone
+--FILE--
+<?php
+
+date_default_timezone_set('America/Los_Angeles');
+var_dump(DateTime::createFromFormat('Y/m/d H:i:s', '1995/06/08 12:34:56',
null));
+var_dump(DateTimeImmutable::createFromFormat('Y/m/d H:i:s', '1995/06/08
12:34:56', null));
+--EXPECT--
+object(DateTime)#1 (3) {
+ ["date"]=>
+ string(26) "1995-06-08 12:34:56.000000"
+ ["timezone_type"]=>
+ int(3)
+ ["timezone"]=>
+ string(19) "America/Los_Angeles"
+}
+object(DateTimeImmutable)#1 (3) {
+ ["date"]=>
+ string(26) "1995-06-08 12:34:56.000000"
+ ["timezone_type"]=>
+ int(3)
+ ["timezone"]=>
+ string(19) "America/Los_Angeles"
+}