PHP 5.4.4ではphp.iniでdate.timezoneの設定が必要

PHP 5.3.2でもphp.iniでdate.timezoneの設定が必要だったが(参照「PHP 5.3.2ではdate.timezoneの設定が必要」)、PHP 5.4.4でも同じくその設定は必要だった。

※PHP 5.4.4(Windows版)のphp.iniのデフォルト設定(初期設定)となるphp.ini-developmentファイル、php.ini-productionファイルを確認すると、どちらもdate.timezoneは空になっている。date.timezoneが空のままだと、date、getdate、phpinfoなどの関数を実行すると、以下のようなエラーが表示される。

《Windows 7のコマンド プロンプトでphp.iniのdate.timezoneを空にしてgetdate関数を実行した例》

php -r "print_r(getdate());"
PHP Warning: getdate(): 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 Command line code on line 1

Warning: getdate(): 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 Command line code on line 1

このエラーを解消するには、php.iniの「date.timezone」に「Asia/Tokyo」など適切なタイムゾーンを設定すればよい。

《php.iniのdate.timezoneに「Asia/Tokyo」を設定する例》

<設定前>

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

<設定後>

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

コマンドプロンプトでコマンドラインでPHPを実行している場合は、上記のようにphp.iniを修正するだけでエラーは解消される。ApacheからPHPを実行している場合は、Apacheの再起動後にエラーが解消される。

前へ

PHP 5.4.4 Windows版のphp.ini-productionファイル

次へ

義農公園のプール(義農プール)が平成24年度に取り壊されるらしい