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: 2017-10-24 07:52 UTC
Votes:2
Avg. Score:3.5 ± 0.5
Reproduced:0 of 0 (0.0%)
From: eric at wepay dot com Assigned:
Status: Open Package: Date/time related
PHP Version: 5.3.2 OS: OS X, Centos 5
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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:
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC