|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-12-06 10:45 UTC] aharvey@php.net
-Status: Open
+Status: Duplicate
[2010-12-06 10:45 UTC] aharvey@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 13:00:01 2025 UTC |
Description: ------------ ‘PHP Warning: date(): It is not safe to rely on the system's timezone settings.’ The warning is ridiculous. It is not safe to drive a car, yet most people do it every day. And the remedy offered creates more problems that it solves (AFAIK, it tries to solve the problem that the system administrator is incompetent, which is not a problem of most system administrators, and it is none of PHP’s business after all). There are several workarounds for this warning, and none of them is good. The workaround contained in the warning actually does more harm than good. There are numerous places where a configuration parameter can be set, including live code. The configuration files for various virtual servers can be different. If the time zone changes, e.g. when the application uses an outsourced server, ALL these places must be updated. There is no standard way to specify sysconf change triggers, and even if there was one, the trouble of doing is not justified by the advantage of specifying the time zone for PHP separately (which is none). The workaround of calling the date_default_timezone_set() function is more appealing but it suffers the same disadvantages. Because it must be done for every single script that uses date, the only reasonable place to put it is in a script preloaded to PHP. However, there is no reasonable way to reliably configure such a script system-wide, so it might work and it might also fail. Again, the advantage to implementing this tautology is NONE. There is also a third workaround, not mentioned in the warning message, to set the environment variable TZ: TZ="$(date '+%Z')" This is least pain but setting this environment variable is EXPLICITLY DISCOURAGED by the documentation of GNU C library. There is also no COMPILE-TIME SETTING to disable this warning. Please provide one and please turn it on when PHP is to be linked against glibc. Thank you. Test script: --------------- <?php echo date('r'), "\n"; ?> Expected result: ---------------- Sat, 04 Dec 2010 20:15:14 +0100 Actual result: -------------- PHP Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Berlin' for 'CET/1.0/no DST' instead in Command line code on line 1 Sat, 04 Dec 2010 20:15:14 +0100