I have briefly tested a patch that largely reverts the 8.2 behaviour, built on top of the two debian timezone patches.

I don't have a full understanding of how these functions interact, so there might be corner cases not covered, but it is possible to get the old behaviour back, especially in the default case.
--- php_date.c.orig	2024-04-24 14:16:54.806434417 -0400
+++ php_date.c	2024-04-24 14:58:45.176360415 -0400
@@ -259,7 +259,7 @@
 
 /* {{{ INI Settings */
 PHP_INI_BEGIN()
-	STD_PHP_INI_ENTRY("date.timezone", "UTC", PHP_INI_ALL, OnUpdate_date_timezone, default_timezone, zend_date_globals, date_globals)
+	STD_PHP_INI_ENTRY("date.timezone", "", 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)
@@ -377,6 +377,7 @@
 	date_globals->default_timezone = NULL;
 	date_globals->timezone = NULL;
 	date_globals->tzcache = NULL;
+	date_globals->timezone_valid = 0;
 }
 /* }}} */
 
@@ -512,18 +513,19 @@
 /* {{{ static PHP_INI_MH(OnUpdate_date_timezone) */
 static PHP_INI_MH(OnUpdate_date_timezone)
 {
-	if (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"
-		);
+	if (OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage) == FAILURE) {
 		return FAILURE;
 	}
 
-	if (OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage) == FAILURE) {
-		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;
+		}
 	}
 
 	return SUCCESS;
@@ -547,6 +549,11 @@
 			return Z_STRVAL_P(ztz);
 		}
 	} else if (*DATEG(default_timezone)) {
+		if (DATEG(timezone_valid) == 1) {
+			return DATEG(default_timezone);
+		}
+
+		DATEG(timezone_valid) = 1;
 		return DATEG(default_timezone);
 	}
 	/* Try to guess timezone from system information */
--- php_date.h.orig	2024-04-24 14:59:46.843329549 -0400
+++ php_date.h	2024-04-24 14:41:48.409328857 -0400
@@ -108,6 +108,7 @@
 	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)

Reply via email to