bug78139.phpt 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. --TEST--
  2. Bug #78139 (timezone_open accepts invalid timezone string argument)
  3. --FILE--
  4. <?php
  5. $strings = [
  6. "x",
  7. "x UTC",
  8. "xx UTC",
  9. "xUTC",
  10. "UTCx",
  11. "UTC xx",
  12. ];
  13. foreach ($strings as $string)
  14. {
  15. echo "Parsing '{$string}':\n";
  16. $tz = timezone_open($string);
  17. var_dump($tz);
  18. try {
  19. $tz = new \DateTimeZone($string);
  20. } catch (Exception $e) {
  21. echo $e->getMessage(), "\n";
  22. }
  23. echo "\n\n";
  24. }
  25. ?>
  26. --EXPECTF--
  27. Parsing 'x':
  28. object(DateTimeZone)#1 (2) {
  29. ["timezone_type"]=>
  30. int(2)
  31. ["timezone"]=>
  32. string(1) "X"
  33. }
  34. Parsing 'x UTC':
  35. Warning: timezone_open(): Unknown or bad timezone (x UTC) in %sbug78139.php on line %d
  36. bool(false)
  37. DateTimeZone::__construct(): Unknown or bad timezone (x UTC)
  38. Parsing 'xx UTC':
  39. Warning: timezone_open(): Unknown or bad timezone (xx UTC) in %sbug78139.php on line %d
  40. bool(false)
  41. DateTimeZone::__construct(): Unknown or bad timezone (xx UTC)
  42. Parsing 'xUTC':
  43. Warning: timezone_open(): Unknown or bad timezone (xUTC) in %sbug78139.php on line %d
  44. bool(false)
  45. DateTimeZone::__construct(): Unknown or bad timezone (xUTC)
  46. Parsing 'UTCx':
  47. Warning: timezone_open(): Unknown or bad timezone (UTCx) in %sbug78139.php on line %d
  48. bool(false)
  49. DateTimeZone::__construct(): Unknown or bad timezone (UTCx)
  50. Parsing 'UTC xx':
  51. Warning: timezone_open(): Unknown or bad timezone (UTC xx) in %sbug78139.php on line %d
  52. bool(false)
  53. DateTimeZone::__construct(): Unknown or bad timezone (UTC xx)