xref: /PHP-7.2/ext/date/tests/bug51866.phpt (revision 4b85f1d4)
1--TEST--
2Bug #51866 (Lenient parsing with parseFromFormat)
3--FILE--
4<?php
5date_default_timezone_set('UTC');
6
7$tests = array(
8	array( 'Y-m-d',   '2001-11-29 13:20:01' ),
9	array( 'Y-m-d+',  '2001-11-29 13:20:01' ),
10	array( 'Y-m-d +', '2001-11-29 13:20:01' ),
11	array( 'Y-m-d+',  '2001-11-29' ),
12	array( 'Y-m-d +', '2001-11-29' ),
13	array( 'Y-m-d +', '2001-11-29 ' ),
14);
15foreach( $tests as $test )
16{
17	list($format, $str) = $test;
18	var_dump($format, $str);
19	$d = DateTime::createFromFormat($format, $str);
20	var_dump($d);
21	var_dump(DateTime::getLastErrors());
22
23	echo "\n\n";
24}
25--EXPECTF--
26string(5) "Y-m-d"
27string(19) "2001-11-29 13:20:01"
28bool(false)
29array(4) {
30  ["warning_count"]=>
31  int(0)
32  ["warnings"]=>
33  array(0) {
34  }
35  ["error_count"]=>
36  int(1)
37  ["errors"]=>
38  array(1) {
39    [10]=>
40    string(13) "Trailing data"
41  }
42}
43
44
45string(6) "Y-m-d+"
46string(19) "2001-11-29 13:20:01"
47object(DateTime)#%d (3) {
48  ["date"]=>
49  string(26) "2001-11-29 %d:%d:%d.%d"
50  ["timezone_type"]=>
51  int(3)
52  ["timezone"]=>
53  string(%d) "%s"
54}
55array(4) {
56  ["warning_count"]=>
57  int(1)
58  ["warnings"]=>
59  array(1) {
60    [10]=>
61    string(13) "Trailing data"
62  }
63  ["error_count"]=>
64  int(0)
65  ["errors"]=>
66  array(0) {
67  }
68}
69
70
71string(7) "Y-m-d +"
72string(19) "2001-11-29 13:20:01"
73object(DateTime)#%d (3) {
74  ["date"]=>
75  string(26) "2001-11-29 %d:%d:%d.%d"
76  ["timezone_type"]=>
77  int(3)
78  ["timezone"]=>
79  string(%d) "%s"
80}
81array(4) {
82  ["warning_count"]=>
83  int(1)
84  ["warnings"]=>
85  array(1) {
86    [11]=>
87    string(13) "Trailing data"
88  }
89  ["error_count"]=>
90  int(0)
91  ["errors"]=>
92  array(0) {
93  }
94}
95
96
97string(6) "Y-m-d+"
98string(10) "2001-11-29"
99object(DateTime)#%d (3) {
100  ["date"]=>
101  string(26) "2001-11-29 %d:%d:%d.%d"
102  ["timezone_type"]=>
103  int(3)
104  ["timezone"]=>
105  string(%d) "%s"
106}
107array(4) {
108  ["warning_count"]=>
109  int(0)
110  ["warnings"]=>
111  array(0) {
112  }
113  ["error_count"]=>
114  int(0)
115  ["errors"]=>
116  array(0) {
117  }
118}
119
120
121string(7) "Y-m-d +"
122string(10) "2001-11-29"
123bool(false)
124array(4) {
125  ["warning_count"]=>
126  int(0)
127  ["warnings"]=>
128  array(0) {
129  }
130  ["error_count"]=>
131  int(1)
132  ["errors"]=>
133  array(1) {
134    [10]=>
135    string(12) "Data missing"
136  }
137}
138
139
140string(7) "Y-m-d +"
141string(11) "2001-11-29 "
142object(DateTime)#%d (3) {
143  ["date"]=>
144  string(26) "2001-11-29 %d:%d:%d.%d"
145  ["timezone_type"]=>
146  int(3)
147  ["timezone"]=>
148  string(%d) "%s"
149}
150array(4) {
151  ["warning_count"]=>
152  int(0)
153  ["warnings"]=>
154  array(0) {
155  }
156  ["error_count"]=>
157  int(0)
158  ["errors"]=>
159  array(0) {
160  }
161}
162