|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-03-02 15:54 UTC] ryan_a_martin at yahoo dot com
Description:
------------
Since PHP functions like strtotime, mktime, and date_parse do not catch well-formatted but invalid dates like 2009-02-30 and 2010-11-31, it is necessary to use checkdate() to catch them. All documentation pages that document functions intended for accepting Gregorian dates should list checkdate() in their "See Also" sections.
Test script:
---------------
print_r(date_parse('2009-02-30'));
print_r(strtotime('2010-11-31'));
Expected result:
----------------
For date_parse, error_count > 0 and an error thrown. For strtotime, an error thrown, not a UNIX timestamp. Since this does not happen, we need the documentation to make clear that these functions do not validate Gregorian dates, and that a call to checkdate() is required to catch such dates.
Actual result:
--------------
Array ( [year] => 2009 [month] => 2 [day] => 30 [hour] => [minute] => [second] => [fraction] => [warning_count] => 0 [warnings] => Array ( ) [error_count] => 0 [errors] => Array ( ) [is_localtime] => ) 1291179600
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 07 08:00:02 2026 UTC |
Test script was invalid: ---------- <?php print_r(date_parse('2009-02-30')); echo strtotime('2010-11-31'); ?>FYI, later versions of PHP 5.3 do add a warning: derick@whisky:~$ php <?php print_r(date_parse('2009-02-30')); ?> Array ( [year] => 2009 [month] => 2 [day] => 30 [hour] => [minute] => [second] => [fraction] => [warning_count] => 1 [warnings] => Array ( [11] => The parsed date was invalid ) [error_count] => 0 [errors] => Array ( ) [is_localtime] => ) derick@whisky:~$ php -v PHP 5.3.6-dev (cli) (built: Feb 2 2011 11:15:39) (DEBUG)