php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48334 DateTime2 sometimes allows construct with an invalid string
Submitted: 2009-05-19 15:53 UTC Modified: 2009-05-19 16:06 UTC
From: tom at ix dot tc Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.2.9 OS: Windows Vista
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: tom at ix dot tc
New email:
PHP Version: OS:

 

 [2009-05-19 15:53 UTC] tom at ix dot tc
Description:
------------
I was initialising DateTime objects to test validity of date strings when I came across an odd bug. The string "East Anglia" gets parsed the same way as some time today.

Strangely, strtotime does not parse the string.

Reproduce code:
---------------
$date = new DateTime('AAAAA');
echo $date->format('U');

will correctly throw an exception: Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct() [<a href='datetime.--construct'>datetime.--construct</a>]: Failed to parse time string (AAA) at position 0 (A):


$date = new DateTime('East Anglia');
echo $date->format('U');

Gets parsed as if it were now + 7 hours.



Expected result:
----------------
An exception:  Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct() [<a href='datetime.--construct'>datetime.--construct</a>]: Failed to parse time string (AAA) at position 0 (A):

Actual result:
--------------
Gets parsed as a time string.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-19 16:06 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This is not a bug, it is parsed like this:

php -r 'var_dump(date_parse( "East Anglia" ));'

As you can see it sees "EAST" as timezone, and Anglia as "double timezone"... the parser ignores this second timezone specification because in some cases you see "CEST GMT+02".
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 13 15:01:33 2025 UTC