diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 98408ad245ba6..c7097903f268d 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -224,7 +224,7 @@ static PHP_INI_MH(OnUpdate_date_timezone); /* {{{ INI Settings */ PHP_INI_BEGIN() - STD_PHP_INI_ENTRY("date.timezone", "", PHP_INI_ALL, OnUpdate_date_timezone, default_timezone, zend_date_globals, date_globals) + STD_PHP_INI_ENTRY("date.timezone", "UTC", PHP_INI_ALL, OnUpdate_date_timezone, default_timezone, zend_date_globals, date_globals) PHP_INI_ENTRY("date.default_latitude", DATE_DEFAULT_LATITUDE, PHP_INI_ALL, NULL) PHP_INI_ENTRY("date.default_longitude", DATE_DEFAULT_LONGITUDE, PHP_INI_ALL, NULL) PHP_INI_ENTRY("date.sunset_zenith", DATE_SUNSET_ZENITH, PHP_INI_ALL, NULL) @@ -342,7 +342,6 @@ static PHP_GINIT_FUNCTION(date) date_globals->default_timezone = NULL; date_globals->timezone = NULL; date_globals->tzcache = NULL; - date_globals->timezone_valid = 0; } /* }}} */ @@ -478,19 +477,18 @@ timelib_tzinfo *php_date_parse_tzfile_wrapper(const char *formal_tzname, const t /* {{{ static PHP_INI_MH(OnUpdate_date_timezone) */ static PHP_INI_MH(OnUpdate_date_timezone) { - if (OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage) == FAILURE) { + if (new_value && ZSTR_VAL(new_value) && !timelib_timezone_id_is_valid(ZSTR_VAL(new_value), DATE_TIMEZONEDB)) { + php_error_docref( + NULL, E_WARNING, + "Invalid date.timezone value '%s', using '%s' instead", + ZSTR_VAL(new_value), + DATEG(default_timezone) ? DATEG(default_timezone) : "UTC" + ); return FAILURE; } - DATEG(timezone_valid) = 0; - if (stage == PHP_INI_STAGE_RUNTIME) { - if (!timelib_timezone_id_is_valid(DATEG(default_timezone), DATE_TIMEZONEDB)) { - if (DATEG(default_timezone) && *DATEG(default_timezone)) { - php_error_docref(NULL, E_WARNING, "Invalid date.timezone value '%s', we selected the timezone 'UTC' for now.", DATEG(default_timezone)); - } - } else { - DATEG(timezone_valid) = 1; - } + if (OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage) == FAILURE) { + return FAILURE; } return SUCCESS; @@ -500,7 +498,7 @@ static PHP_INI_MH(OnUpdate_date_timezone) /* {{{ Helper functions */ static char* guess_timezone(const timelib_tzdb *tzdb) { - /* Checking configure timezone */ + /* Checking whether timezone has been set with date_default_timezone_set() */ if (DATEG(timezone) && (strlen(DATEG(timezone))) > 0) { return DATEG(timezone); } @@ -514,16 +512,6 @@ static char* guess_timezone(const timelib_tzdb *tzdb) return Z_STRVAL_P(ztz); } } else if (*DATEG(default_timezone)) { - if (DATEG(timezone_valid) == 1) { - return DATEG(default_timezone); - } - - if (!timelib_timezone_id_is_valid(DATEG(default_timezone), tzdb)) { - php_error_docref(NULL, E_WARNING, "Invalid date.timezone value '%s', we selected the timezone 'UTC' for now.", DATEG(default_timezone)); - return "UTC"; - } - - DATEG(timezone_valid) = 1; return DATEG(default_timezone); } /* Fallback to UTC */ diff --git a/ext/date/php_date.h b/ext/date/php_date.h index 129f3617617a7..a4729ff58ffeb 100644 --- a/ext/date/php_date.h +++ b/ext/date/php_date.h @@ -108,7 +108,6 @@ ZEND_BEGIN_MODULE_GLOBALS(date) char *timezone; HashTable *tzcache; timelib_error_container *last_errors; - int timezone_valid; ZEND_END_MODULE_GLOBALS(date) #define DATEG(v) ZEND_MODULE_GLOBALS_ACCESSOR(date, v) diff --git a/ext/date/tests/bug73239.phpt b/ext/date/tests/bug73239.phpt new file mode 100644 index 0000000000000..ea5eec4bdd7dd --- /dev/null +++ b/ext/date/tests/bug73239.phpt @@ -0,0 +1,13 @@ +--TEST-- +Bug #73239 (Odd warning/exception message with invalid timezones) +--FILE-- +getMessage(), "\n"; +} +?> +--EXPECTF-- +Warning: ini_set(): Invalid date.timezone value 'dummy', using 'UTC' instead in %sbug73239.php on line %d diff --git a/ext/date/tests/date_default_timezone_get-1.phpt b/ext/date/tests/date_default_timezone_get-1.phpt index fc466d411d1ec..3164ba7554ee6 100644 --- a/ext/date/tests/date_default_timezone_get-1.phpt +++ b/ext/date/tests/date_default_timezone_get-1.phpt @@ -13,5 +13,6 @@ date.timezone= echo date('e'), "\n"; ?> --EXPECT-- +Warning: PHP Startup: Invalid date.timezone value '', using 'UTC' instead in Unknown on line 0 UTC UTC diff --git a/ext/date/tests/date_default_timezone_get-2.phpt b/ext/date/tests/date_default_timezone_get-2.phpt index 44d94cd76f2a3..d79d8de07a4a2 100644 --- a/ext/date/tests/date_default_timezone_get-2.phpt +++ b/ext/date/tests/date_default_timezone_get-2.phpt @@ -12,4 +12,5 @@ date.timezone= echo date_default_timezone_get(), "\n"; ?> --EXPECT-- +Warning: PHP Startup: Invalid date.timezone value '', using 'UTC' instead in Unknown on line 0 UTC diff --git a/ext/date/tests/date_default_timezone_get-4.phpt b/ext/date/tests/date_default_timezone_get-4.phpt index f2319856d8ee2..dc9fac3ee9070 100644 --- a/ext/date/tests/date_default_timezone_get-4.phpt +++ b/ext/date/tests/date_default_timezone_get-4.phpt @@ -7,5 +7,5 @@ date.timezone=Incorrect/Zone echo date_default_timezone_get(), "\n"; ?> --EXPECTF-- -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 +Warning: PHP Startup: Invalid date.timezone value 'Incorrect/Zone', using 'UTC' instead in %s on line %d UTC diff --git a/ext/date/tests/date_default_timezone_set-1.phpt b/ext/date/tests/date_default_timezone_set-1.phpt index 54f1fa73f3b00..d4e5d9157ceaa 100644 --- a/ext/date/tests/date_default_timezone_set-1.phpt +++ b/ext/date/tests/date_default_timezone_set-1.phpt @@ -21,7 +21,8 @@ date.timezone= echo date(DATE_ISO8601, $date3), "\n"; echo date(DATE_ISO8601, $date4), "\n"; ?> ---EXPECT-- +--EXPECTF-- +Warning: PHP Startup: Invalid date.timezone value '', using 'UTC' instead in %s on line %d America/Indiana/Knox 2005-01-12T03:00:00-0500 2005-07-12T03:00:00-0500 diff --git a/ext/date/tests/ini_set_incorrect-002.phpt b/ext/date/tests/ini_set_incorrect-002.phpt new file mode 100644 index 0000000000000..b54b1c4bb485b --- /dev/null +++ b/ext/date/tests/ini_set_incorrect-002.phpt @@ -0,0 +1,24 @@ +--TEST-- +Test invalid time zone and defaults +--FILE-- + +--EXPECTF-- +UTC + +Warning: ini_set(): Invalid date.timezone value 'foo', using 'UTC' instead in %sini_set_incorrect-002.php on line %d +UTC +Europe/London + +Warning: ini_set(): Invalid date.timezone value 'Mars/Valles_Marineris', using 'Europe/London' instead in %sini_set_incorrect-002.php on line %d +Europe/London diff --git a/ext/date/tests/ini_set_incorrect.phpt b/ext/date/tests/ini_set_incorrect.phpt index 1077333591087..d5746883fcfba 100644 --- a/ext/date/tests/ini_set_incorrect.phpt +++ b/ext/date/tests/ini_set_incorrect.phpt @@ -7,4 +7,4 @@ ini_set("date.timezone", "Incorrect/Zone"); ?> --EXPECTF-- -Warning: ini_set(): Invalid date.timezone value 'Incorrect/Zone', we selected the timezone 'UTC' for now. in %sini_set_incorrect.php on line %d +Warning: ini_set(): Invalid date.timezone value 'Incorrect/Zone', using 'UTC' instead in %sini_set_incorrect.php on line %d diff --git a/ext/intl/tests/dateformat_invalid_timezone.phpt b/ext/intl/tests/dateformat_invalid_timezone.phpt index f5f08c1b8eab6..f618502c2fd00 100644 --- a/ext/intl/tests/dateformat_invalid_timezone.phpt +++ b/ext/intl/tests/dateformat_invalid_timezone.phpt @@ -14,5 +14,6 @@ try { echo $e->getMessage(); } ?> ---EXPECT-- -IntlDateFormatter::__construct(): Invalid date.timezone value 'Mars/Utopia_Planitia', we selected the timezone 'UTC' for now. +--EXPECTF-- +Warning: PHP Startup: Invalid date.timezone value 'Mars/Utopia_Planitia', using 'UTC' instead in %s on line %d +Wat? diff --git a/sapi/cli/tests/006.phpt b/sapi/cli/tests/006.phpt index 4f33e37c71089..1f2af9c6b6358 100644 --- a/sapi/cli/tests/006.phpt +++ b/sapi/cli/tests/006.phpt @@ -11,7 +11,7 @@ if (PCRE_JIT_SUPPORT == false) { } ?> --INI-- -date.timezone= +date.timezone=UTC --FILE--