xref: /PHP-8.1/ext/date/tests/bug78139.phpt (revision d5e57268)
1--TEST--
2Bug #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
14foreach ($strings as $string)
15{
16	echo "Parsing '{$string}':\n";
17
18	$tz = timezone_open($string);
19	var_dump($tz);
20
21	try {
22		$tz = new \DateTimeZone($string);
23	} catch (Exception $e) {
24		echo $e->getMessage(), "\n";
25	}
26
27	echo "\n\n";
28}
29?>
30--EXPECTF--
31Parsing 'x':
32object(DateTimeZone)#1 (2) {
33  ["timezone_type"]=>
34  int(2)
35  ["timezone"]=>
36  string(1) "X"
37}
38
39
40Parsing 'x UTC':
41
42Warning: timezone_open(): Unknown or bad timezone (x UTC) in %sbug78139.php on line %d
43bool(false)
44DateTimeZone::__construct(): Unknown or bad timezone (x UTC)
45
46
47Parsing 'xx UTC':
48
49Warning: timezone_open(): Unknown or bad timezone (xx UTC) in %sbug78139.php on line %d
50bool(false)
51DateTimeZone::__construct(): Unknown or bad timezone (xx UTC)
52
53
54Parsing 'xUTC':
55
56Warning: timezone_open(): Unknown or bad timezone (xUTC) in %sbug78139.php on line %d
57bool(false)
58DateTimeZone::__construct(): Unknown or bad timezone (xUTC)
59
60
61Parsing 'UTCx':
62
63Warning: timezone_open(): Unknown or bad timezone (UTCx) in %sbug78139.php on line %d
64bool(false)
65DateTimeZone::__construct(): Unknown or bad timezone (UTCx)
66
67
68Parsing 'UTC xx':
69
70Warning: timezone_open(): Unknown or bad timezone (UTC xx) in %sbug78139.php on line %d
71bool(false)
72DateTimeZone::__construct(): Unknown or bad timezone (UTC xx)
73
74