问题
I've been getting this warning every time I run a command in the terminal. It started with a recent update of all of my homebrew formulas and updating composer. I've had a look into the file it's referencing but not sure what to do here.
Full message
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 the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /Users/ste/.composer/vendor/hoa/core/Parameter.php on line 158
On line 158 of Parameter.php we have a function
/**
* Initialize constants.
*
* @return void
*/
public static function initializeConstants()
{
$c = explode('…', date('d…j…N…w…z…W…m…n…Y…y…g…G…h…H…i…s…u…O…T…U'));
self::$_constants = [
'd' => $c[0],
'j' => $c[1],
'N' => $c[2],
'w' => $c[3],
'z' => $c[4],
'W' => $c[5],
'm' => $c[6],
'n' => $c[7],
'Y' => $c[8],
'y' => $c[9],
'g' => $c[10],
'G' => $c[11],
'h' => $c[12],
'H' => $c[13],
'i' => $c[14],
's' => $c[15],
'u' => $c[16],
'O' => $c[17],
'T' => $c[18],
'U' => $c[19]
];
return;
}'
I don't use PHP on OS X at all. My work is via VMs or MAMP the odd time so I'm not sure if one should be playing around with the core of Composer?
回答1:
You need to set the time zone, either using php.ini or with the php function date_default_timezone_set().
Via php.ini:
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = Europe/London
Or using php:
date_default_timezone_set("Europe/London");
回答2:
Use date_default_timezone_set to set your default timezone. Or add date.timezone = // your timezone in php.ini. https://secure.php.net/manual/en/timezones.php has the list of supported timezones in php.
来源:https://stackoverflow.com/questions/36371618/php-warning-date-it-is-not-safe-to-rely-on-the-systems-timezone-settings