xref: /PHP-7.1/tests/classes/bug65768.phpt (revision 5f099446)
1--TEST--
2Bug #65768: date_diff accepts only DateTime instance even though docs say about DateTimeInterface
3--INI--
4date.timezone=Europe/London
5--FILE--
6<?php
7
8$dt1 = new DateTime("2010-10-20");
9$dti1 = new DateTimeImmutable("2010-10-25");
10$dti2 = new DateTimeImmutable("2010-10-28");
11
12$diff1 = $dt1->diff($dti1);
13echo $diff1->y, " ", $diff1->m, " ", $diff1->d, " ",
14     $diff1->h, " ", $diff1->i, " ", $diff1->s, "\n";
15
16$diff2 = $dti1->diff($dti2);
17echo $diff2->y, " ", $diff2->m, " ", $diff2->d, " ",
18     $diff2->h, " ", $diff2->i, " ", $diff2->s, "\n";
19
20$diff3 = date_diff($dt1, $dti2);
21echo $diff3->y, " ", $diff3->m, " ", $diff3->d, " ",
22     $diff3->h, " ", $diff3->i, " ", $diff3->s, "\n";
23
24class cdt1 extends DateTime implements DateTimeInterface {}
25
26class cdt2 extends DateTimeImmutable implements DateTimeInterface {}
27
28class cdt3 implements DateTimeInterface {}
29
30?>
31--EXPECTF--
320 0 5 0 0 0
330 0 3 0 0 0
340 0 8 0 0 0
35
36Fatal error: DateTimeInterface can't be implemented by user classes in %sbug65768.php on line %d
37