php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #51993 DateTime::getLastErrors should be an instance method, not static
Submitted: 2010-06-03 23:51 UTC Modified: 2022-05-13 13:13 UTC
Votes:2
Avg. Score:3.5 ± 0.5
Reproduced:0 of 0 (0.0%)
From: eric at wepay dot com Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 5.3.2 OS: OS X, Centos 5
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: eric at wepay dot com
New email:
PHP Version: OS:

 

 [2010-06-03 23:51 UTC] 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
        (
        )

)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-06-08 14:33 UTC] felipe@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: derick
 [2017-10-24 07:52 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: derick +Assigned To:
 [2022-05-13 13:13 UTC] derick@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: derick
 [2022-05-13 13:13 UTC] derick@php.net
If this is still desirable, please file an issue at https://github.com/php/php-src/issues/
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 22:01:27 2024 UTC