DateTime_clone_basic2.phpt 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. --TEST--
  2. Test clone of objects whose 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 whose 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. --EXPECTF--
  26. *** Testing clone on objects whose class derived from DateTime class ***
  27. object(DateTimeExt1)#%d (5) {
  28. ["property1"]=>
  29. int(99)
  30. ["property2"]=>
  31. string(5) "Hello"
  32. ["date"]=>
  33. string(26) "2009-02-03 12:34:41.000000"
  34. ["timezone_type"]=>
  35. int(2)
  36. ["timezone"]=>
  37. string(3) "GMT"
  38. }
  39. object(DateTimeExt1)#%d (5) {
  40. ["property1"]=>
  41. int(99)
  42. ["property2"]=>
  43. string(5) "Hello"
  44. ["date"]=>
  45. string(26) "2009-02-03 12:34:41.000000"
  46. ["timezone_type"]=>
  47. int(2)
  48. ["timezone"]=>
  49. string(3) "GMT"
  50. }
  51. object(DateTimeExt2)#%d (7) {
  52. ["property1"]=>
  53. int(99)
  54. ["property2"]=>
  55. string(5) "Hello"
  56. ["property3"]=>
  57. bool(true)
  58. ["property4"]=>
  59. float(10.5)
  60. ["date"]=>
  61. string(26) "2009-02-03 12:34:41.000000"
  62. ["timezone_type"]=>
  63. int(2)
  64. ["timezone"]=>
  65. string(3) "GMT"
  66. }
  67. object(DateTimeExt2)#%d (7) {
  68. ["property1"]=>
  69. int(99)
  70. ["property2"]=>
  71. string(5) "Hello"
  72. ["property3"]=>
  73. bool(true)
  74. ["property4"]=>
  75. float(10.5)
  76. ["date"]=>
  77. string(26) "2009-02-03 12:34:41.000000"
  78. ["timezone_type"]=>
  79. int(2)
  80. ["timezone"]=>
  81. string(3) "GMT"
  82. }