From:             bugs dot php dot net at majkl578 dot cz
Operating system: -
PHP version:      5.5.0beta1
Package:          Date/time related
Bug Type:         Bug
Bug description:DateTimeImmutable is incompatible with DateTime and leads to BC 
breaks

Description:
------------
PHP 5.5 adds DateTimeImmutable, which extends DateTime.

As Benjamin Eberlei already pointed out in internals list [1], the behavior
is not compatible with each other and therefore the inheritance seems to be
wrong.
This bad implementation is not backward compatible and may lead to serious
problems with existing code.

Here are some examples which would get broken (bad behavior or even
infinite loop!) by passing DateTimeImmutable instead of DateTime.


function testOne(DateTime $dt)
{
        for ($i = 1; $i <= 2; $i++, $dt->modify('first day of next month')) {
                echo $dt->format('Y/m/d'), PHP_EOL;
        }
}

testOne(new DateTime());
// 2013/03/25
// 2013/04/01

testOne(new DateTimeImmutable());
// 2013/03/25
// 2013/03/25

-------------------

function testTwo(DateTime $from, DateTime $to)
{
        for ($current = clone $from; $current <= $to; $current->modify('+ 1 
day'))
{
                echo $current->format('Y/m/d'), PHP_EOL;
        }
}

testTwo(new DateTime(), new DateTime('+ 1 day'));
// 2013/03/25
// 2013/03/26

testTwo(new DateTimeImmutable(), new DateTimeImmutable('+ 1 day'));
// 2013/03/25
// 2013/03/25
// 2013/03/25
// infinite loop occurs!



This clearly shows what side-effects might this "feature" have.

Please, do not add another badly designed feature and revert it before 5.5
gets released.


[1] http://marc.info/?l=php-internals&m=136135370215794&w=2


-- 
Edit bug report at https://bugs.php.net/bug.php?id=64513&edit=1
-- 
Try a snapshot (PHP 5.4):   
https://bugs.php.net/fix.php?id=64513&r=trysnapshot54
Try a snapshot (PHP 5.3):   
https://bugs.php.net/fix.php?id=64513&r=trysnapshot53
Try a snapshot (trunk):     
https://bugs.php.net/fix.php?id=64513&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=64513&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=64513&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=64513&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=64513&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=64513&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=64513&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=64513&r=notwrong
Not enough info:            
https://bugs.php.net/fix.php?id=64513&r=notenoughinfo
Submitted twice:            
https://bugs.php.net/fix.php?id=64513&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=64513&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=64513&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=64513&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=64513&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=64513&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=64513&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=64513&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=64513&r=mysqlcfg

Reply via email to