note 112683 added to function.date-default-timezone-get
| From: | benrwhite at gmail dot com | Date: | Fri, 12 Jul 2013 11:31:54 +0000 |
| Subject: | note 112683 added to function.date-default-timezone-get | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-195583@lists.php.net to get a copy of this message | ||
For the reason that date_default_timezone_get() throws an error when the timezone isn't set in
php.ini and then returns a default chosen by the system (rather than returning false to indicate to
the script that a timezone hasn't been set), I've found that the following works when you
want a script to detect when the ini value has not been set and want the script itself to choose a
default in that case, while still allowing bootstrap scripts to set their own default using
date_default_timezone_set().
<?php
set_error_handler(function ($errno, $errstr){
throw new Exception($errstr);
return false;
});
try{
date_default_timezone_get();
}
catch(Exception $e){
date_default_timezone_set('UTC'); // Sets to UTC if not specified anywhere in .ini
}
restore_error_handler();
----
Server IP: 69.147.83.199
Probable Submitter: 78.141.1.194
----
Manual Page -- http://php.net/manual/en/function.date-default-timezone-get.php
Edit -- https://master.php.net/note/edit/112683
Del: integrated -- https://master.php.net/note/delete/112683/integrated
Del: useless -- https://master.php.net/note/delete/112683/useless
Del: bad code -- https://master.php.net/note/delete/112683/bad+code
Del: spam -- https://master.php.net/note/delete/112683/spam
Del: non-english -- https://master.php.net/note/delete/112683/non-english
Del: in docs -- https://master.php.net/note/delete/112683/in+docs
Del: other reasons-- https://master.php.net/note/delete/112683
Reject -- https://master.php.net/note/reject/112683
Search -- https://master.php.net/manage/user-notes.php