note 85252 added to function.strtotime
| From: | php at info-svc dot com | Date: | Fri, 22 Aug 2008 04:31:00 +0000 |
| Subject: | note 85252 added to function.strtotime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-143734@lists.php.net to get a copy of this message | ||
"5.1.0 Now issues the E_STRICT and E_NOTICE time zone errors."
This little footnote represents a failure mode under common conditions, which is extremely
frustrating. For example, this code ALWAYS returns an error on PHP 5:
ini_set('error_reporting', E_ALL|E_STRICT);
echo strtotime('Sun, 20 Jul 2008 23:34:07 GMT', time());
Notice a standard HTTP-date was specified, so the PHP timezone setting will never affect the value
returned by strtotime().
There is no documented workaround, and the suggested methods including date_default_timezone_get
will cause the same errors. To make matters worse, those functions don't exist in older
versions.
Based on my testing, it is necessary to provide PHP with a hard-coded timezone, any timezone at all,
to prevent the error. Since the timezone has no affect on the results, I could use 'UTC'
or 'America/Detroit' or any other valid string.
if (function_exists('date_default_timezone_set')) {
date_default_timezone_set('UTC');
}
echo strtotime('Sun, 20 Jul 2008 23:34:07 GMT', time());
This is the only solution I have found so far.
Enjoy
Robert Chapin
Chapin Information Services
----
Server IP: 69.147.83.197
Probable Submitter: 99.144.157.75
----
Manual Page -- http://www.php.net/manual/en/function.strtotime.php
Edit -- https://master.php.net/note/edit/85252
Del: integrated -- https://master.php.net/note/delete/85252/integrated
Del: useless -- https://master.php.net/note/delete/85252/useless
Del: bad code -- https://master.php.net/note/delete/85252/bad+code
Del: spam -- https://master.php.net/note/delete/85252/spam
Del: non-english -- https://master.php.net/note/delete/85252/non-english
Del: in docs -- https://master.php.net/note/delete/85252/in+docs
Del: other reasons-- https://master.php.net/note/delete/85252
Reject -- https://master.php.net/note/reject/85252
Search -- https://master.php.net/manage/user-notes.php