I'm a bit annoyed of keeping PHP's time zone updated. I really love that everything else on my system trusts that I'm maintaining the system's time zone correctly. Maybe there might be use cases where it could be beneficial to configure PHP differently, but why does PHP warn me about relying on my time zone is not safe?
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.
Because Derick said so. That's why. This internals mailing list thread will tell you all about the "logic" behind this decision. The date.timezone
warning is a constant annoyance for anyone using PHP as a programming language and not as a replacement for knowing how to write code.
More specifically, this behavior drives me nuts. I wouldn't normally abuse the SO Q&A system to vent but this warning drives me bananas. Also, it's April 1 so why not?
Here's what PHP devs say about it (in the related discussion):
No - you, as an admin, are required to make an informed decision on what you want your timezone to be. There have been way too many bug reports where people had no clue, so now we throw a warning.
Derick Rethans is the author of this commit that turned date_warning from E_STRICT
(in PHP 5.2-) to E_WARNING
(PHP 5.3+).
The same discussion has quite a sound (yet obviously awkward) solution to this, applied by MediaWiki:
Actually, the sensible default is what
guess_timezone()
does already, except without the warnings. You can get that behaviour with e.g.date_default_timezone_set( @date_default_timezone_get() );
at the top of your program. That's what MediaWiki does (except with by modifying
error_reporting
instead of using@
). We stole the idea from another web app. It's more convenient than duplicating the functionality ofguess_timezone()
in the application.It's Derick's prerogative to annoy all users half to death with warnings, as his way of indicating his distaste for the state of OS support for querying of system timezone. That's the reward we give him for writing lots of date/time code.
The key part of this workaround is date_default_timezone_get
function, which, in order, returns the default timezone by...
date_default_timezone_set()
function (if any)PHP 5.3.0
)date.timezone
ini option (if set)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With