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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 02 06:01:28 2024 UTC