1--TEST--
2Test of compare object handler for DateTime objects
3--FILE--
4<?php
5
6echo "Simple test for DateTime compare object handler\n";
7
8//Set the default time zone
9date_default_timezone_set("Europe/London");
10
11class DateTimeExt1 extends DateTime {
12}
13
14class DateTimeExt2 extends DateTime{
15    public $foo = "Hello";
16    private $bar = 99;
17}
18
19class DateTimeExt3 extends DateTimeExt2 {
20}
21
22$obj1 = new DateTime("2009-02-12 12:47:41 GMT");
23$obj2 = new DateTimeExt1("2009-02-12 12:47:41 GMT");
24$obj3 = new DateTimeExt2("2009-02-12 12:47:41 GMT");
25$obj4 = new DateTimeExt3("2009-02-12 12:47:41 GMT");
26
27echo "\n-- All the following tests should compare equal --\n";
28var_dump($obj1 == $obj1);
29var_dump($obj1 == $obj2);
30var_dump($obj1 == $obj3);
31var_dump($obj1 == $obj4);
32var_dump($obj2 == $obj3);
33var_dump($obj2 == $obj4);
34var_dump($obj3 == $obj4);
35
36date_modify($obj1, "+1 day");
37echo "\n-- The following test should still compare equal --\n";
38var_dump($obj1 == $obj1);
39echo "\n-- All the following tests should now compare NOT equal --\n";
40var_dump($obj1 == $obj2);
41var_dump($obj1 == $obj3);
42var_dump($obj1 == $obj4);
43
44echo "\n-- All the following tests should again compare equal --\n";
45date_modify($obj2, "+1 day");
46date_modify($obj3, "+1 day");
47date_modify($obj4, "+1 day");
48var_dump($obj1 == $obj2);
49var_dump($obj1 == $obj3);
50var_dump($obj1 == $obj4);
51?>
52--EXPECT--
53Simple test for DateTime compare object handler
54
55-- All the following tests should compare equal --
56bool(true)
57bool(true)
58bool(true)
59bool(true)
60bool(true)
61bool(true)
62bool(true)
63
64-- The following test should still compare equal --
65bool(true)
66
67-- All the following tests should now compare NOT equal --
68bool(false)
69bool(false)
70bool(false)
71
72-- All the following tests should again compare equal --
73bool(true)
74bool(true)
75bool(true)
76