DateTime_extends_basic1.phpt 914 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. --TEST--
  2. Test DateTime class inheritance
  3. --FILE--
  4. <?php
  5. //Set the default time zone
  6. date_default_timezone_set("Europe/London");
  7. echo "*** Testing basic DateTime inheritance() ***\n";
  8. class DateTimeExt extends DateTime
  9. {
  10. public static $format = "F j, Y, g:i:s a";
  11. public function __toString()
  12. {
  13. return parent::format(self::$format);
  14. }
  15. }
  16. echo "\n-- Create an instance of DateTimeExt --\n";
  17. $d = new DateTimeExt("1967-05-01 22:30:41");
  18. echo "\n-- Invoke __toString --\n";
  19. echo $d . "\n";
  20. echo "\n -- modify date and time --\n";
  21. $d->setDate(1963, 7, 2);
  22. $d->setTime(10, 45, 30);
  23. echo "\n-- Invoke __toString again --\n";
  24. echo $d . "\n";
  25. ?>
  26. ===DONE===
  27. --EXPECTF--
  28. *** Testing basic DateTime inheritance() ***
  29. -- Create an instance of DateTimeExt --
  30. -- Invoke __toString --
  31. May 1, 1967, 10:30:41 pm
  32. -- modify date and time --
  33. -- Invoke __toString again --
  34. July 2, 1963, 10:45:30 am
  35. ===DONE===