php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65787 DateTime::__construct() accepts all single letters except 'j' as valid timezone
Submitted: 2013-09-29 15:13 UTC Modified: 2013-09-29 22:46 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: vascowhite at gmail dot com Assigned:
Status: Duplicate Package: Date/time related
PHP Version: 5.5.4 OS: All?
Private report: No CVE-ID: None
 [2013-09-29 15:13 UTC] vascowhite at gmail dot com
Description:
------------
If just a single letter is passed to the constructor of \DateTime it is accepted 
as a valid timezone string. Except, for some strange reason, the letter 'j'.

Test script:
---------------
$date = new \DateTime('a');
var_dump($date);

Expected result:
----------------
I expect an exception to be raised with the message:-

Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): 
Failed to parse time string (a) at position 0 (a): The timezone could not be found 
in the database' 

Actual result:
--------------
Except for when the letter 'j' is passed a DateTime object is created. For example 
the following code:-

$date = new \DateTime('a');
var_dump($date);

Will give the following output:-

object(DateTime)[1]
  public 'date' => string '2013-09-29 15:17:19' (length=19)
  public 'timezone_type' => int 2
  public 'timezone' => string 'A' (length=1)


Where it should raise an exception.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-09-29 15:56 UTC] vascowhite at gmail dot com
I just found that this is a duplicate of bug #65747
 [2013-09-29 22:46 UTC] requinix@php.net
-Status: Open +Status: Duplicate
 [2013-09-29 22:46 UTC] requinix@php.net
Single letters except "j" correspond to a military timezone.
http://en.wikipedia.org/wiki/List_of_military_time_zones

(I've marked the other report as a doc bug accordingly.)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 11:01:30 2024 UTC