DateTime_serialize.phpt 930 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. --TEST--
  2. Test serialization of DateTime objects
  3. --FILE--
  4. <?php
  5. //Set the default time zone
  6. date_default_timezone_set("Europe/London");
  7. $date1 = new DateTime("2005-07-14 22:30:41");
  8. var_dump($date1);
  9. $serialized = serialize($date1);
  10. var_dump($serialized);
  11. $date2 = unserialize($serialized);
  12. var_dump($date2);
  13. // Try to use unserialzied object
  14. var_dump( $date2->format( "F j, Y, g:i a") );
  15. ?>
  16. ===DONE===
  17. --EXPECTF--
  18. object(DateTime)#%d (3) {
  19. ["date"]=>
  20. string(26) "2005-07-14 22:30:41.000000"
  21. ["timezone_type"]=>
  22. int(3)
  23. ["timezone"]=>
  24. string(13) "Europe/London"
  25. }
  26. string(125) "O:8:"DateTime":3:{s:4:"date";s:26:"2005-07-14 22:30:41.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:13:"Europe/London";}"
  27. object(DateTime)#%d (3) {
  28. ["date"]=>
  29. string(26) "2005-07-14 22:30:41.000000"
  30. ["timezone_type"]=>
  31. int(3)
  32. ["timezone"]=>
  33. string(13) "Europe/London"
  34. }
  35. string(23) "July 14, 2005, 10:30 pm"
  36. ===DONE===