php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65313 DateTime::getLastErrors() does not include default timezone problems
Submitted: 2013-07-23 03:15 UTC Modified: 2015-06-12 17:44 UTC
From: four dot zero dot one dot unauthorized at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: Date/time related
PHP Version: 5.4.17 OS: any
Private report: No CVE-ID: None
 [2013-07-23 03:15 UTC] four dot zero dot one dot unauthorized at gmail dot com
Description:
------------
When ever date.timezone INI setting or date_default_timezone_set() is used and a clearly invalid timezone ID is set, DateTime::getLastErrors() has no indication of this.  Same if no timezone is set.

Test script:
---------------
// assume date.timezone currently set to "America/Los_Angeles" for this test
date_default_timezone_set( "asdf" );
try {
	$d = new DateTime();
}
catch ( Exception $ex ) {
	var_dump( DateTime::getLastErrors() ); // never even reached - $d is actually valid and set to "America/Los_Angeles" timezone, and DateTime::getLastErrors() has no errors listed
}

ini_set( "date.timezone",  "asdf" );
try {
	$d = new DateTime();
}
catch ( Exception $ex ) {
	var_dump( DateTime::getLastErrors() ); // reached, but no errors listed here
}

Expected result:
----------------
DateTime::getLastErrors() always contains the "The timezone could not be found in the database" error if a bad timezone name is preset, or "You are *required* to use the date.timezone setting or the date_default_timezone_set() function" error if no timezone name is preset.

Actual result:
--------------
DateTime::getLastErrors() contains no such errors or warnings.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-06-12 17:44 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2015-06-12 17:44 UTC] cmb@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

When an invalid timezone specifier is passed to
date_default_timezone_set() it is simply ignored, and that
already triggers a notice. If that notice is not enough, check the
return value of date_default_timezone_set():

| This function returns FALSE if the timezone_identifier isn't
| valid, or TRUE otherwise.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jun 13 03:01:33 2024 UTC