DateTime_compare_basic1.phpt 1.7 KB

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