Forum Moderators: coopster

Message Too Old, No Replies

PHP date() function throws E STRICT error

         

coopster

6:16 pm on Jul 20, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I was testing on a dev box today that is running PHP 5.1.2 and received the following error:


Strict Standards: date() function.date [php.net]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable 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 'America/Chicago' for '-5.0/DST' instead in <snipped path and script> on line 74

The function still worked fine and with error suppression you will never see the issue. However, it seems you can not just have a bare date() function any longer in STRICT error_reporting mode unless you have set the default timezone. Although this could be set using the Example from the PHP date() [php.net] manual page ...


// set the default timezone to use. Available since PHP 5.1 
date_default_timezone_set [php.net]('UTC');

... I didn't want to have to be doing that on every invocation of the date() function. It is a lot easier to set in the

php.ini
. I set it to UTC on the dev box ...
[Date] 
; Defines the default timezone used by the date functions
date.timezone = UTC

The timezone options can be found in the Appendix [php.net] which is linked from the PHP Date and Time Functions [php.net] page. You'll have to set yours accordingly.

Just wanted to give others a heads up if you are planning or running any PHP 5.1.x boxes.

eelixduppy

6:22 pm on Jul 20, 2006 (gmt 0)



Thanks for the heads up, coopster. I was just in the process of upgrading to PHP 5.1.4; kind of an odd coincidence ;)