Skip to content

Commit 365f428

Browse files
committed
Allow the third arg to DateTime(Immutable)::createFromFormat() to be null.
Permit the same meaning as not passing the arg at all.
1 parent ef19072 commit 365f428

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

ext/date/php_date.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2628,7 +2628,7 @@ PHP_FUNCTION(date_create_from_format)
26282628
size_t time_str_len = 0, format_str_len = 0;
26292629
zval datetime_object;
26302630

2631-
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) {
2631+
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) {
26322632
RETURN_FALSE;
26332633
}
26342634

@@ -2651,7 +2651,7 @@ PHP_FUNCTION(date_create_immutable_from_format)
26512651
size_t time_str_len = 0, format_str_len = 0;
26522652
zval datetime_object;
26532653

2654-
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) {
2654+
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) {
26552655
RETURN_FALSE;
26562656
}
26572657

ext/date/tests/bug68669.phpt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
DateTime::createFromFormat() does not allow NULL $timezone
3+
--FILE--
4+
<?php
5+
6+
date_default_timezone_set('America/Los_Angeles');
7+
var_dump(DateTime::createFromFormat('Y/m/d H:i:s', '1995/06/08 12:34:56', null));
8+
var_dump(DateTimeImmutable::createFromFormat('Y/m/d H:i:s', '1995/06/08 12:34:56', null));
9+
--EXPECT--
10+
object(DateTime)#1 (3) {
11+
["date"]=>
12+
string(26) "1995-06-08 12:34:56.000000"
13+
["timezone_type"]=>
14+
int(3)
15+
["timezone"]=>
16+
string(19) "America/Los_Angeles"
17+
}
18+
object(DateTimeImmutable)#1 (3) {
19+
["date"]=>
20+
string(26) "1995-06-08 12:34:56.000000"
21+
["timezone_type"]=>
22+
int(3)
23+
["timezone"]=>
24+
string(19) "America/Los_Angeles"
25+
}

0 commit comments

Comments
 (0)