DateTime_extends_basic1.phpt 903 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. --EXPECT--
  27. *** Testing basic DateTime inheritance() ***
  28. -- Create an instance of DateTimeExt --
  29. -- Invoke __toString --
  30. May 1, 1967, 10:30:41 pm
  31. -- modify date and time --
  32. -- Invoke __toString again --
  33. July 2, 1963, 10:45:30 am