Skip to content

Commit 171ebb1

Browse files
committed
Merged pull request #8594
2 parents bbc738e + 63aa5a4 commit 171ebb1

11 files changed

+58
-30
lines changed

ext/date/php_date.c

+11-23
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ static PHP_INI_MH(OnUpdate_date_timezone);
224224

225225
/* {{{ INI Settings */
226226
PHP_INI_BEGIN()
227-
STD_PHP_INI_ENTRY("date.timezone", "", PHP_INI_ALL, OnUpdate_date_timezone, default_timezone, zend_date_globals, date_globals)
227+
STD_PHP_INI_ENTRY("date.timezone", "UTC", PHP_INI_ALL, OnUpdate_date_timezone, default_timezone, zend_date_globals, date_globals)
228228
PHP_INI_ENTRY("date.default_latitude", DATE_DEFAULT_LATITUDE, PHP_INI_ALL, NULL)
229229
PHP_INI_ENTRY("date.default_longitude", DATE_DEFAULT_LONGITUDE, PHP_INI_ALL, NULL)
230230
PHP_INI_ENTRY("date.sunset_zenith", DATE_SUNSET_ZENITH, PHP_INI_ALL, NULL)
@@ -342,7 +342,6 @@ static PHP_GINIT_FUNCTION(date)
342342
date_globals->default_timezone = NULL;
343343
date_globals->timezone = NULL;
344344
date_globals->tzcache = NULL;
345-
date_globals->timezone_valid = 0;
346345
}
347346
/* }}} */
348347

@@ -478,19 +477,18 @@ timelib_tzinfo *php_date_parse_tzfile_wrapper(const char *formal_tzname, const t
478477
/* {{{ static PHP_INI_MH(OnUpdate_date_timezone) */
479478
static PHP_INI_MH(OnUpdate_date_timezone)
480479
{
481-
if (OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage) == FAILURE) {
480+
if (new_value && ZSTR_VAL(new_value) && !timelib_timezone_id_is_valid(ZSTR_VAL(new_value), DATE_TIMEZONEDB)) {
481+
php_error_docref(
482+
NULL, E_WARNING,
483+
"Invalid date.timezone value '%s', using '%s' instead",
484+
ZSTR_VAL(new_value),
485+
DATEG(default_timezone) ? DATEG(default_timezone) : "UTC"
486+
);
482487
return FAILURE;
483488
}
484489

485-
DATEG(timezone_valid) = 0;
486-
if (stage == PHP_INI_STAGE_RUNTIME) {
487-
if (!timelib_timezone_id_is_valid(DATEG(default_timezone), DATE_TIMEZONEDB)) {
488-
if (DATEG(default_timezone) && *DATEG(default_timezone)) {
489-
php_error_docref(NULL, E_WARNING, "Invalid date.timezone value '%s', we selected the timezone 'UTC' for now.", DATEG(default_timezone));
490-
}
491-
} else {
492-
DATEG(timezone_valid) = 1;
493-
}
490+
if (OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage) == FAILURE) {
491+
return FAILURE;
494492
}
495493

496494
return SUCCESS;
@@ -500,7 +498,7 @@ static PHP_INI_MH(OnUpdate_date_timezone)
500498
/* {{{ Helper functions */
501499
static char* guess_timezone(const timelib_tzdb *tzdb)
502500
{
503-
/* Checking configure timezone */
501+
/* Checking whether timezone has been set with date_default_timezone_set() */
504502
if (DATEG(timezone) && (strlen(DATEG(timezone))) > 0) {
505503
return DATEG(timezone);
506504
}
@@ -514,16 +512,6 @@ static char* guess_timezone(const timelib_tzdb *tzdb)
514512
return Z_STRVAL_P(ztz);
515513
}
516514
} else if (*DATEG(default_timezone)) {
517-
if (DATEG(timezone_valid) == 1) {
518-
return DATEG(default_timezone);
519-
}
520-
521-
if (!timelib_timezone_id_is_valid(DATEG(default_timezone), tzdb)) {
522-
php_error_docref(NULL, E_WARNING, "Invalid date.timezone value '%s', we selected the timezone 'UTC' for now.", DATEG(default_timezone));
523-
return "UTC";
524-
}
525-
526-
DATEG(timezone_valid) = 1;
527515
return DATEG(default_timezone);
528516
}
529517
/* Fallback to UTC */

ext/date/php_date.h

-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ ZEND_BEGIN_MODULE_GLOBALS(date)
108108
char *timezone;
109109
HashTable *tzcache;
110110
timelib_error_container *last_errors;
111-
int timezone_valid;
112111
ZEND_END_MODULE_GLOBALS(date)
113112

114113
#define DATEG(v) ZEND_MODULE_GLOBALS_ACCESSOR(date, v)

ext/date/tests/bug73239.phpt

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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', using 'UTC' instead in %sbug73239.php on line %d

ext/date/tests/date_default_timezone_get-1.phpt

+1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ date.timezone=
1313
echo date('e'), "\n";
1414
?>
1515
--EXPECT--
16+
Warning: PHP Startup: Invalid date.timezone value '', using 'UTC' instead in Unknown on line 0
1617
UTC
1718
UTC

ext/date/tests/date_default_timezone_get-2.phpt

+1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ date.timezone=
1212
echo date_default_timezone_get(), "\n";
1313
?>
1414
--EXPECT--
15+
Warning: PHP Startup: Invalid date.timezone value '', using 'UTC' instead in Unknown on line 0
1516
UTC

ext/date/tests/date_default_timezone_get-4.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ date.timezone=Incorrect/Zone
77
echo date_default_timezone_get(), "\n";
88
?>
99
--EXPECTF--
10-
Warning: date_default_timezone_get(): Invalid date.timezone value 'Incorrect/Zone', we selected the timezone 'UTC' for now. in %sdate_default_timezone_get-4.php on line %d
10+
Warning: PHP Startup: Invalid date.timezone value 'Incorrect/Zone', using 'UTC' instead in %s on line %d
1111
UTC

ext/date/tests/date_default_timezone_set-1.phpt

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ date.timezone=
2121
echo date(DATE_ISO8601, $date3), "\n";
2222
echo date(DATE_ISO8601, $date4), "\n";
2323
?>
24-
--EXPECT--
24+
--EXPECTF--
25+
Warning: PHP Startup: Invalid date.timezone value '', using 'UTC' instead in %s on line %d
2526
America/Indiana/Knox
2627
2005-01-12T03:00:00-0500
2728
2005-07-12T03:00:00-0500
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Test invalid time zone and defaults
3+
--FILE--
4+
<?php
5+
echo ini_get("date.timezone"), "\n";
6+
7+
ini_set("date.timezone", "foo");
8+
echo ini_get("date.timezone"), "\n";
9+
10+
ini_set("date.timezone", "Europe/London");
11+
echo ini_get("date.timezone"), "\n";
12+
13+
ini_set("date.timezone", "Mars/Valles_Marineris");
14+
echo ini_get("date.timezone"), "\n";
15+
?>
16+
--EXPECTF--
17+
UTC
18+
19+
Warning: ini_set(): Invalid date.timezone value 'foo', using 'UTC' instead in %sini_set_incorrect-002.php on line %d
20+
UTC
21+
Europe/London
22+
23+
Warning: ini_set(): Invalid date.timezone value 'Mars/Valles_Marineris', using 'Europe/London' instead in %sini_set_incorrect-002.php on line %d
24+
Europe/London

ext/date/tests/ini_set_incorrect.phpt

+1-1
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', using 'UTC' instead in %sini_set_incorrect.php on line %d

ext/intl/tests/dateformat_invalid_timezone.phpt

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ try {
1414
echo $e->getMessage();
1515
}
1616
?>
17-
--EXPECT--
18-
IntlDateFormatter::__construct(): Invalid date.timezone value 'Mars/Utopia_Planitia', we selected the timezone 'UTC' for now.
17+
--EXPECTF--
18+
Warning: PHP Startup: Invalid date.timezone value 'Mars/Utopia_Planitia', using 'UTC' instead in %s on line %d
19+
Wat?

sapi/cli/tests/006.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ if (PCRE_JIT_SUPPORT == false) {
1111
}
1212
?>
1313
--INI--
14-
date.timezone=
14+
date.timezone=UTC
1515
--FILE--
1616
<?php
1717

0 commit comments

Comments
 (0)