DateTime_compare_basic1.phpt 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. ===DONE===
  44. --EXPECT--
  45. Simple test for DateTime compare object handler
  46. -- All the following tests should compare equal --
  47. bool(true)
  48. bool(true)
  49. bool(true)
  50. bool(true)
  51. bool(true)
  52. bool(true)
  53. bool(true)
  54. -- The following test should still compare equal --
  55. bool(true)
  56. -- All the following tests should now compare NOT equal --
  57. bool(false)
  58. bool(false)
  59. bool(false)
  60. -- All the following tests should again compare equal --
  61. bool(true)
  62. bool(true)
  63. bool(true)
  64. ===DONE===