Req #51993 [Asn->Opn]: DateTime::getLastErrors should be an instance method, not static
| From: | kalle@php.net | Date: | Tue, 24 Oct 2017 07:52:29 +0000 |
| Subject: | Req #51993 [Asn->Opn]: DateTime::getLastErrors should be an instance method, not static | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-212171@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: kalle@php.net
Reported by: eric at wepay dot com
Summary: DateTime::getLastErrors should be an instance
method, not static
-Status: Assigned
+Status: Open
Type: Feature/Change Request
Package: Date/time related
Operating System: OS X, Centos 5
PHP Version: 5.3.2
-Assigned To: derick
+Assigned To:
Block user comment: N
Private report: N
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