Skip to content

Commit 6a93be0

Browse files
committed
Fixed bug #73239 (DateTime shows strange error message with invalid timezone)
1 parent f2ac4f2 commit 6a93be0

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ PHP NEWS
99
. Fixed Haiku ZTS builds. (David Carlier)
1010

1111
- Date:
12+
. Fixed bug #73239 (DateTime constructor throws exceptions when it should
13+
not). (Derick)
1214
. Fixed bug GH-8471 (Segmentation fault when converting immutable and mutable
1315
DateTime instances created using reflection). (Derick)
1416

ext/date/php_date.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ static PHP_INI_MH(OnUpdate_date_timezone)
505505
if (stage == PHP_INI_STAGE_RUNTIME) {
506506
if (!timelib_timezone_id_is_valid(DATEG(default_timezone), DATE_TIMEZONEDB)) {
507507
if (DATEG(default_timezone) && *DATEG(default_timezone)) {
508-
php_error_docref(NULL, E_WARNING, "Invalid date.timezone value '%s', we selected the timezone 'UTC' for now.", DATEG(default_timezone));
508+
php_error_docref(NULL, E_WARNING, "Invalid date.timezone value '%s'", DATEG(default_timezone));
509509
}
510510
} else {
511511
DATEG(timezone_valid) = 1;
@@ -538,7 +538,7 @@ static char* guess_timezone(const timelib_tzdb *tzdb)
538538
}
539539

540540
if (!timelib_timezone_id_is_valid(DATEG(default_timezone), tzdb)) {
541-
php_error_docref(NULL, E_WARNING, "Invalid date.timezone value '%s', we selected the timezone 'UTC' for now.", DATEG(default_timezone));
541+
php_error_docref(NULL, E_WARNING, "Invalid date.timezone value '%s'", DATEG(default_timezone));
542542
return "UTC";
543543
}
544544

ext/date/tests/bug73239.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Bug #73239 (Odd warning/exception message with invalid timezones)
3+
--FILE--
4+
<?php
5+
ini_set('date.timezone', 'dummy');
6+
try {
7+
$dt = new DateTime('now');
8+
} catch (Exception $e) {
9+
echo $e->getMessage(), "\n";
10+
}
11+
?>
12+
--EXPECTF--
13+
Warning: ini_set(): Invalid date.timezone value 'dummy' in %sbug73239.php on line %d
14+
DateTime::__construct(): Invalid date.timezone value 'dummy', we selected the timezone 'UTC' for now.

ext/date/tests/ini_set_incorrect.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ ini_set("date.timezone", "Incorrect/Zone");
77

88
?>
99
--EXPECTF--
10-
Warning: ini_set(): Invalid date.timezone value 'Incorrect/Zone', we selected the timezone 'UTC' for now. in %sini_set_incorrect.php on line %d
10+
Warning: ini_set(): Invalid date.timezone value 'Incorrect/Zone' in %sini_set_incorrect.php on line %d

0 commit comments

Comments
 (0)