It's raining cats and dogs.

無駄なことなんてないはず

php5.4からデフォルトのtimezoneの扱いが変わっている件

結構今更感あるんだけど、php5.4からデフォルトのtimezoneの扱いが変わっている。

php5.4以上をインストールしてデフォルトのphp.iniのままphpを実行したりすると以下のようなメッセージが出る。

PHP Warning:  Unknown: 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 the timezone 'UTC' for now, but please set date.timezone to select your timezone. in Unknown on line 0

なんとなく読んでみると、とりあえずUTCタイムゾーンを設定しているけど、date.timezoneでうまいこと設定してねって話。

で、その辺りの話がdate_default_timezone_get()関数のマニュアルに書いてあった。

http://www.php.net/manual/ja/function.date-default-timezone-get.php

要は

  • 5.4以前はTZ環境変数とかみてくれたり、ホストOSに問い合わせてタイムゾーンを設定してくれていたりしていた。
  • 5.5からは明示的にdate_default_timezone_set()関数で設定するか、php.iniのdate.timezone に設定してくれ。

とのことらしい。

php.iniを見てみるとdate.timezoneはコメントアウトされているので

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = Asia/Tokyo

とか設定したらおk