slimphp / Slim-Skeleton

Slim Framework 4 Skeleton Application
http://www.slimframework.com
MIT License
1.59k stars 479 forks source link

Timezone error #14

Closed PascalPixel closed 10 years ago

PascalPixel commented 10 years ago

First time clean install of this repo:

Fatal error: Uncaught exception 'ErrorException' with message 'date_default_timezone_get(): 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/Superpencil/Desktop/Sour/vendor/monolog/monolog/src/Monolog/Logger.php:214 Stack trace: #0 [internal function]: Slim\Slim::handleErrors(2, 'date_default_ti...', '/Users/Superpen...', 214, Array) #1 /Users/Superpencil/Desktop/Sour/vendor/monolog/monolog/src/Monolog/Logger.php(214): date_default_timezone_get() #2 /Users/Superpencil/Desktop/Sour/vendor/monolog/monolog/src/Monolog/Logger.php(507): Monolog\Logger->addRecord(400, Object(ErrorException), Array) #3 /Users/Superpencil/Desktop/Sour/vendor/slim/slim/Slim/Middleware/PrettyExceptions.php(72): Mo in /Users/Superpencil/Desktop/Sour/vendor/monolog/monolog/src/Monolog/Logger.php on line 214

Adding this to the index.php fixes it

// Set default timezone
date_default_timezone_set('America/New_York');
jeremykendall commented 10 years ago

Thanks for the report, @Superpencil. I'm actually going to leave this as is and not add date_default_timezone_set() to the example for this reason:

It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting ...

While adding date_default_timezone_set will fix the issue, IMHO it's best practice to always set date.timezone in php.ini. Updating that setting and restarting your webserver will also resolve the issue, and I'd prefer to push developers in that direction.

FWIW, I use both techniques in my personal projects. I use date.timezone in my php.ini but I also set it in most apps since I don't trust servers I deploy on if I don't control them :smile:

PascalPixel commented 10 years ago

Thanks for the detailed explanation! Makes perfect sense, and if people run into trouble they'll find this closed issue now :)