DateTime_serialize.phpt 903 B

12345678910111213141516171819202122232425262728293031323334353637
  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. --EXPECTF--
  17. object(DateTime)#%d (3) {
  18. ["date"]=>
  19. string(26) "2005-07-14 22:30:41.000000"
  20. ["timezone_type"]=>
  21. int(3)
  22. ["timezone"]=>
  23. string(13) "Europe/London"
  24. }
  25. 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";}"
  26. object(DateTime)#%d (3) {
  27. ["date"]=>
  28. string(26) "2005-07-14 22:30:41.000000"
  29. ["timezone_type"]=>
  30. int(3)
  31. ["timezone"]=>
  32. string(13) "Europe/London"
  33. }
  34. string(23) "July 14, 2005, 10:30 pm"