Edit report at http://bugs.php.net/bug.php?id=51993&edit=1
ID: 51993 Updated by: [email protected] Reported by: eric at wepay dot com Summary: DateTime::getLastErrors should be an instance method, not static -Status: Open +Status: Assigned Type: Feature/Change Request Package: Date/time related Operating System: OS X, Centos 5 PHP Version: 5.3.2 -Assigned To: +Assigned To: derick Previous Comments: ------------------------------------------------------------------------ [2010-06-03 23:51:11] eric at wepay dot com Description: ------------ When using the DateTime class, it would make more sense to have getLastErrors be an instance method rather than a static method. That way, when creating a series of DateTime objects, you can check each one individually for errors. Currently it works as _documented_, but not in a very logical/useful way. Alternately, a getErrors() instance method that could sit alongside the getLastErrors() static method would be just as useful. Test script: --------------- <?php date_default_timezone_set('America/Los_Angeles'); $a = array( DateTime::createFromFormat('Y m d', '2009 01 31'), DateTime::createFromFormat('Y m d', '2009 02 28'), DateTime::createFromFormat('Y m d', '2009 02 29'), // 2009 not leap year DateTime::createFromFormat('Y m d', '2008 02 29'), // 2008 is leap year ); foreach ($a as $b) { print_r($b->getLastErrors()); } Expected result: ---------------- Array ( [warning_count] => 0 [warnings] => Array ( ) [error_count] => 0 [errors] => Array ( ) ) Array ( [warning_count] => 0 [warnings] => Array ( ) [error_count] => 0 [errors] => Array ( ) ) Array ( [warning_count] => 1 [warnings] => Array ( [10] => The parsed date was invalid ) [error_count] => 0 [errors] => Array ( ) ) Array ( [warning_count] => 0 [warnings] => Array ( ) [error_count] => 0 [errors] => Array ( ) ) Actual result: -------------- Array ( [warning_count] => 0 [warnings] => Array ( ) [error_count] => 0 [errors] => Array ( ) ) Array ( [warning_count] => 0 [warnings] => Array ( ) [error_count] => 0 [errors] => Array ( ) ) Array ( [warning_count] => 0 [warnings] => Array ( ) [error_count] => 0 [errors] => Array ( ) ) Array ( [warning_count] => 0 [warnings] => Array ( ) [error_count] => 0 [errors] => Array ( ) ) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=51993&edit=1
