Req #51993 [Opn->Csd]: DateTime::getLastErrors should be an instance method, not static
| From: | derick@php.net | Date: | Fri, 13 May 2022 13:13:19 +0000 |
| Subject: | Req #51993 [Opn->Csd]: DateTime::getLastErrors should be an instance method, not static | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-241485@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=51993&edit=1
ID: 51993
Updated by: derick@php.net
Reported by: eric at wepay dot com
Summary: DateTime::getLastErrors should be an instance
method, not static
-Status: Open
+Status: Closed
Type: Feature/Change Request
Package: Date/time related
Operating System: OS X, Centos 5
PHP Version: 5.3.2
-Assigned To:
+Assigned To: derick
Block user comment: N
Private report: N
New Comment:
If this is still desirable, please file an issue at https://github.com/php/php-src/issues/
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 https://bugs.php.net/bug.php?id=51993&edit=1