Skip to content

Commit ce76ec5

Browse files
committed
Merge branch 'PHP-5.5'
2 parents 4084a02 + f3824ad commit ce76ec5

File tree

2 files changed

+43
-16
lines changed

2 files changed

+43
-16
lines changed

ext/date/php_date.c

+39-13
Original file line numberDiff line numberDiff line change
@@ -495,9 +495,11 @@ int php_date_global_timezone_db_enabled;
495495
/* on 90'35; common sunrise declaration (sun body disappeared) */
496496
#define DATE_SUNRISE_ZENITH "90.583333"
497497

498+
static PHP_INI_MH(OnUpdate_date_timezone);
499+
498500
/* {{{ INI Settings */
499501
PHP_INI_BEGIN()
500-
STD_PHP_INI_ENTRY("date.timezone", "", PHP_INI_ALL, OnUpdateString, default_timezone, zend_date_globals, date_globals)
502+
STD_PHP_INI_ENTRY("date.timezone", "", PHP_INI_ALL, OnUpdate_date_timezone, default_timezone, zend_date_globals, date_globals)
501503
PHP_INI_ENTRY("date.default_latitude", DATE_DEFAULT_LATITUDE, PHP_INI_ALL, NULL)
502504
PHP_INI_ENTRY("date.default_longitude", DATE_DEFAULT_LONGITUDE, PHP_INI_ALL, NULL)
503505
PHP_INI_ENTRY("date.sunset_zenith", DATE_SUNSET_ZENITH, PHP_INI_ALL, NULL)
@@ -599,6 +601,7 @@ static PHP_GINIT_FUNCTION(date)
599601
date_globals->default_timezone = NULL;
600602
date_globals->timezone = NULL;
601603
date_globals->tzcache = NULL;
604+
date_globals->timezone_valid = 0;
602605
}
603606
/* }}} */
604607

@@ -843,35 +846,57 @@ timelib_tzinfo *php_date_parse_tzfile_wrapper(char *formal_tzname, const timelib
843846
}
844847
/* }}} */
845848

849+
// created this callback method to check the date.timezone only when changed, to increase performance and error on an ini_set line
850+
/* {{{ static PHP_INI_MH(OnUpdate_date_timezone) */
851+
static PHP_INI_MH(OnUpdate_date_timezone)
852+
{
853+
if (OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC) == FAILURE) {
854+
return FAILURE;
855+
}
856+
857+
DATEG(timezone_valid) = 0;
858+
if (stage == PHP_INI_STAGE_RUNTIME) {
859+
if (!timelib_timezone_id_is_valid(DATEG(default_timezone), DATE_TIMEZONEDB)) {
860+
php_error_docref(NULL TSRMLS_CC, E_WARNING, DATE_TZ_ERRMSG);
861+
} else {
862+
DATEG(timezone_valid) = 1;
863+
}
864+
}
865+
866+
return SUCCESS;
867+
}
868+
/* }}} */
869+
846870
/* {{{ Helper functions */
847871
static char* guess_timezone(const timelib_tzdb *tzdb TSRMLS_DC)
848872
{
849873
/* Checking configure timezone */
850-
if (DATEG(timezone) && (strlen(DATEG(timezone)) > 0)) {
874+
if (DATEG(timezone) && strlen(DATEG(timezone)) > 0) {
851875
return DATEG(timezone);
852876
}
853877
/* Check config setting for default timezone */
854878
if (!DATEG(default_timezone)) {
855879
/* Special case: ext/date wasn't initialized yet */
856880
zval ztz;
857-
858-
if (SUCCESS == zend_get_configuration_directive("date.timezone", sizeof("date.timezone"), &ztz) &&
859-
Z_TYPE(ztz) == IS_STRING &&
860-
Z_STRLEN(ztz) > 0 &&
861-
timelib_timezone_id_is_valid(Z_STRVAL(ztz), tzdb)) {
881+
882+
if (SUCCESS == zend_get_configuration_directive("date.timezone", sizeof("date.timezone"), &ztz) && Z_TYPE(ztz) == IS_STRING && Z_STRLEN(ztz) > 0 && timelib_timezone_id_is_valid(Z_STRVAL(ztz), tzdb)) {
862883
return Z_STRVAL(ztz);
863884
}
864885
} else if (*DATEG(default_timezone)) {
865-
if (timelib_timezone_id_is_valid(DATEG(default_timezone), tzdb)) {
886+
if (DATEG(timezone_valid) == 1) { // timezone already checked and validated
866887
return DATEG(default_timezone);
867888
}
868-
/* Invalid date.timezone value */
869-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid date.timezone value '%s', we selected the timezone 'UTC' for now.", DATEG(default_timezone));
870-
} else {
871-
/* No date.timezone value */
872-
php_error_docref(NULL TSRMLS_CC, E_WARNING, DATE_TZ_ERRMSG "We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone.");
889+
890+
if (!timelib_timezone_id_is_valid(DATEG(default_timezone), tzdb)) {
891+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid date.timezone value '%s', we selected the timezone 'UTC' for now.", DATEG(default_timezone));
892+
return "UTC";
893+
}
894+
895+
DATEG(timezone_valid) = 1;
896+
return DATEG(default_timezone);
873897
}
874898
/* Fallback to UTC */
899+
php_error_docref(NULL TSRMLS_CC, E_WARNING, DATE_TZ_ERRMSG "We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone.");
875900
return "UTC";
876901
}
877902

@@ -889,6 +914,7 @@ PHPAPI timelib_tzinfo *get_timezone_info(TSRMLS_D)
889914
}
890915
/* }}} */
891916

917+
892918
/* {{{ date() and gmdate() data */
893919
#include "ext/standard/php_smart_str.h"
894920

ext/date/php_date.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,11 @@ struct _php_period_obj {
150150
};
151151

152152
ZEND_BEGIN_MODULE_GLOBALS(date)
153-
char *default_timezone;
154-
char *timezone;
155-
HashTable *tzcache;
153+
char *default_timezone;
154+
char *timezone;
155+
HashTable *tzcache;
156156
timelib_error_container *last_errors;
157+
int timezone_valid;
157158
ZEND_END_MODULE_GLOBALS(date)
158159

159160
#ifdef ZTS

0 commit comments

Comments
 (0)