DateTime_clone_basic2.phpt 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. --TEST--
  2. Test clone of objects whoose class derived from DateTime class
  3. --FILE--
  4. <?php
  5. //Set the default time zone
  6. date_default_timezone_set("Europe/London");
  7. class DateTimeExt1 extends DateTime {
  8. public $property1 = 99;
  9. public $property2 = "Hello";
  10. }
  11. class DateTimeExt2 extends DateTimeExt1 {
  12. public $property3 = true;
  13. public $property4 = 10.5;
  14. }
  15. echo "*** Testing clone on objects whoose class derived from DateTime class ***\n";
  16. $d1 = new DateTimeExt1("2009-02-03 12:34:41 GMT");
  17. var_dump($d1);
  18. $d1_clone = clone $d1;
  19. var_dump($d1_clone);
  20. $d2 = new DateTimeExt2("2009-02-03 12:34:41 GMT");
  21. var_dump($d2);
  22. $d2_clone = clone $d2;
  23. var_dump($d2_clone);
  24. ?>
  25. ===DONE===
  26. --EXPECTF--
  27. *** Testing clone on objects whoose class derived from DateTime class ***
  28. object(DateTimeExt1)#%d (5) {
  29. ["property1"]=>
  30. int(99)
  31. ["property2"]=>
  32. string(5) "Hello"
  33. ["date"]=>
  34. string(26) "2009-02-03 12:34:41.000000"
  35. ["timezone_type"]=>
  36. int(2)
  37. ["timezone"]=>
  38. string(3) "GMT"
  39. }
  40. object(DateTimeExt1)#%d (5) {
  41. ["property1"]=>
  42. int(99)
  43. ["property2"]=>
  44. string(5) "Hello"
  45. ["date"]=>
  46. string(26) "2009-02-03 12:34:41.000000"
  47. ["timezone_type"]=>
  48. int(2)
  49. ["timezone"]=>
  50. string(3) "GMT"
  51. }
  52. object(DateTimeExt2)#%d (7) {
  53. ["property3"]=>
  54. bool(true)
  55. ["property4"]=>
  56. float(10.5)
  57. ["property1"]=>
  58. int(99)
  59. ["property2"]=>
  60. string(5) "Hello"
  61. ["date"]=>
  62. string(26) "2009-02-03 12:34:41.000000"
  63. ["timezone_type"]=>
  64. int(2)
  65. ["timezone"]=>
  66. string(3) "GMT"
  67. }
  68. object(DateTimeExt2)#%d (7) {
  69. ["property3"]=>
  70. bool(true)
  71. ["property4"]=>
  72. float(10.5)
  73. ["property1"]=>
  74. int(99)
  75. ["property2"]=>
  76. string(5) "Hello"
  77. ["date"]=>
  78. string(26) "2009-02-03 12:34:41.000000"
  79. ["timezone_type"]=>
  80. int(2)
  81. ["timezone"]=>
  82. string(3) "GMT"
  83. }
  84. ===DONE===