From:             
Operating system: OS X, Centos 5
PHP version:      5.3.2
Package:          Date/time related
Bug Type:         Feature/Change Request
Bug description:DateTime::getLastErrors should be an instance method, not static

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 bug report at http://bugs.php.net/bug.php?id=51993&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=51993&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=51993&r=trysnapshot53
Try a snapshot (trunk):              
http://bugs.php.net/fix.php?id=51993&r=trysnapshottrunk
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=51993&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=51993&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=51993&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=51993&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=51993&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=51993&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=51993&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=51993&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=51993&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=51993&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=51993&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=51993&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=51993&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=51993&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=51993&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=51993&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=51993&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=51993&r=mysqlcfg

Reply via email to