Doc #54139 [Opn]: All date acceptance functions should cross-reference checkdate()

From: Date: Wed, 02 Mar 2011 14:58:52 +0000
Subject: Doc #54139 [Opn]: All date acceptance functions should cross-reference checkdate()
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-6044@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=54139&edit=1 ID: 54139 Updated by: derick@php.net Reported by: ryan_a_martin at yahoo dot com Summary: All date acceptance functions should cross-reference checkdate() Status: Open Type: Documentation Problem Package: Documentation problem Operating System: N/A PHP Version: Irrelevant Block user comment: N Private report: N New Comment: 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) Previous Comments: ------------------------------------------------------------------------ [2011-03-02 15:56:40] ryan_a_martin at yahoo dot com Test script was invalid: ---------- <?php print_r(date_parse('2009-02-30')); echo strtotime('2010-11-31'); ?> ------------------------------------------------------------------------ [2011-03-02 15:54:58] 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 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=54139&edit=1

« previous php.doc.bugs (#6044) next »