php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #42640 error in date_parse function
Submitted: 2007-09-12 08:50 UTC Modified: 2007-12-09 00:24 UTC
From: david at zschille dot net Assigned:
Status: Closed Package: Documentation problem
PHP Version: 5CVS-2007-09-12 (snap) OS: Win XP
Private report: No CVE-ID: None
 [2007-09-12 08:50 UTC] david at zschille dot net
Description:
------------
In the php manual is written that the parameter for date_parse should be a "Date in format accepted by strtotime()" and it "returns array on success or FALSE on failure". So if i give a not valid format to the function i expect a FALSE. 

Also interesting is the behavior of date_parse when i give the string "19044-05-09" to it. It produces no error and no warning message and seems to be valid!? But the string is also valid for strtotime(). Has this function also an error or is this string really valid?

Reproduce code:
---------------
var_dump( date_parse( 'abc123' ) );

Expected result:
----------------
bool false

Actual result:
--------------
array(13) {
  ["year"]=>
  bool(false)
  ["month"]=>
  bool(false)
  ["day"]=>
  bool(false)
  ["hour"]=>
  bool(false)
  ["minute"]=>
  bool(false)
  ["second"]=>
  bool(false)
  ["fraction"]=>
  bool(false)
  ["warning_count"]=>
  int(0)
  ["warnings"]=>
  array(0) {
  }
  ["error_count"]=>
  int(4)
  ["errors"]=>
  array(4) {
    [0]=>
    string(47) "The timezone could not be found in the database"
    [3]=>
    string(20) "Unexpected character"
    [4]=>
    string(20) "Unexpected character"
    [5]=>
    string(20) "Unexpected character"
  }
  ["is_localtime"]=>
  bool(true)
  ["zone_type"]=>
  int(0)
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-09-12 11:09 UTC] jani@php.net
Can you please clarify what is the problem? As you can see, there are errors in the output for "abc123"..and yes, "19044-05-09" is valid date. Just very far in the future.
 [2007-09-12 11:50 UTC] david at zschille dot net
The PHP manual says about the return values: "Returns array on success or FALSE on failure". You can see here that it returns not FALSE but an array. Is the error in the manual or in the behavior of the function?

To the string "19044-05-09": it get parsed as 19:04:00 2004-05-09. This is not correct.
 [2007-09-13 09:44 UTC] jani@php.net
Assigned to the ext/date maintainer.
 [2007-12-08 15:38 UTC] derick@php.net
19044 is not a 4-digit year, so that's why it doesn't get parsed "correctly" - there is a feature request for this already: http://bugs.php.net/bug.php?id=42351

And the other part, this function does not return FALSE, only in case you don't give it a parameter. THis is a documentation issue.
 [2007-12-09 00:24 UTC] felipe@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 16 21:01:33 2025 UTC