diff options
author | nikita2206 <inefedor@gmail.com> | 2013-10-29 19:40:17 +0400 |
---|---|---|
committer | Nikita Popov <nikic@php.net> | 2013-11-29 23:31:07 +0100 |
commit | 5f09944662e09ea0b3f93cfab8702f188955e68c (patch) | |
tree | 31ae7916c62b827b14ab648a0c665634d312d35c /tests/classes | |
parent | 967abd61537a2c7d0beebac9039aa068d518e4eb (diff) | |
download | php-git-5f09944662e09ea0b3f93cfab8702f188955e68c.tar.gz |
Fixed bug #65768: DateTimeImmutable::diff does not work
This commit also prevents user classes from directly implementing
DateTimeInterface, because ext/date relies on classes implementing
it to support certain internal structures.
Diffstat (limited to 'tests/classes')
-rw-r--r-- | tests/classes/bug65768.phpt | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/classes/bug65768.phpt b/tests/classes/bug65768.phpt new file mode 100644 index 0000000000..17ec93cf24 --- /dev/null +++ b/tests/classes/bug65768.phpt @@ -0,0 +1,36 @@ +--TEST-- +Bug #65768: date_diff accepts only DateTime instance even though docs say about DateTimeInterface +--INI-- +date.timezone=Europe/London +--FILE-- +<?php + +$dt1 = new DateTime("2010-10-20"); +$dti1 = new DateTimeImmutable("2010-10-25"); +$dti2 = new DateTimeImmutable("2010-10-28"); + +$diff1 = $dt1->diff($dti1); +echo $diff1->y, " ", $diff1->m, " ", $diff1->d, " ", + $diff1->h, " ", $diff1->i, " ", $diff1->s, "\n"; + +$diff2 = $dti1->diff($dti2); +echo $diff2->y, " ", $diff2->m, " ", $diff2->d, " ", + $diff2->h, " ", $diff2->i, " ", $diff2->s, "\n"; + +$diff3 = date_diff($dt1, $dti2); +echo $diff3->y, " ", $diff3->m, " ", $diff3->d, " ", + $diff3->h, " ", $diff3->i, " ", $diff3->s, "\n"; + +class cdt1 extends DateTime implements DateTimeInterface {} + +class cdt2 extends DateTimeImmutable implements DateTimeInterface {} + +class cdt3 implements DateTimeInterface {} + +?> +--EXPECTF-- +0 0 5 0 0 0 +0 0 3 0 0 0 +0 0 8 0 0 0 + +Fatal error: DateTimeInterface can't be implemented by user classes in %sbug65768.php on line %d |