xref: /PHP-8.1/ext/date/tests/bug51866.phpt (revision b510868b)
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?>
26--EXPECTF--
27string(5) "Y-m-d"
28string(19) "2001-11-29 13:20:01"
29bool(false)
30array(4) {
31  ["warning_count"]=>
32  int(0)
33  ["warnings"]=>
34  array(0) {
35  }
36  ["error_count"]=>
37  int(1)
38  ["errors"]=>
39  array(1) {
40    [10]=>
41    string(13) "Trailing data"
42  }
43}
44
45
46string(6) "Y-m-d+"
47string(19) "2001-11-29 13:20:01"
48object(DateTime)#%d (3) {
49  ["date"]=>
50  string(26) "2001-11-29 %d:%d:%d.%d"
51  ["timezone_type"]=>
52  int(3)
53  ["timezone"]=>
54  string(%d) "%s"
55}
56array(4) {
57  ["warning_count"]=>
58  int(1)
59  ["warnings"]=>
60  array(1) {
61    [10]=>
62    string(13) "Trailing data"
63  }
64  ["error_count"]=>
65  int(0)
66  ["errors"]=>
67  array(0) {
68  }
69}
70
71
72string(7) "Y-m-d +"
73string(19) "2001-11-29 13:20:01"
74object(DateTime)#%d (3) {
75  ["date"]=>
76  string(26) "2001-11-29 %d:%d:%d.%d"
77  ["timezone_type"]=>
78  int(3)
79  ["timezone"]=>
80  string(%d) "%s"
81}
82array(4) {
83  ["warning_count"]=>
84  int(1)
85  ["warnings"]=>
86  array(1) {
87    [11]=>
88    string(13) "Trailing data"
89  }
90  ["error_count"]=>
91  int(0)
92  ["errors"]=>
93  array(0) {
94  }
95}
96
97
98string(6) "Y-m-d+"
99string(10) "2001-11-29"
100object(DateTime)#%d (3) {
101  ["date"]=>
102  string(26) "2001-11-29 %d:%d:%d.%d"
103  ["timezone_type"]=>
104  int(3)
105  ["timezone"]=>
106  string(%d) "%s"
107}
108array(4) {
109  ["warning_count"]=>
110  int(0)
111  ["warnings"]=>
112  array(0) {
113  }
114  ["error_count"]=>
115  int(0)
116  ["errors"]=>
117  array(0) {
118  }
119}
120
121
122string(7) "Y-m-d +"
123string(10) "2001-11-29"
124bool(false)
125array(4) {
126  ["warning_count"]=>
127  int(0)
128  ["warnings"]=>
129  array(0) {
130  }
131  ["error_count"]=>
132  int(1)
133  ["errors"]=>
134  array(1) {
135    [10]=>
136    string(%d) "Not enough data available to satisfy format"
137  }
138}
139
140
141string(7) "Y-m-d +"
142string(11) "2001-11-29 "
143object(DateTime)#%d (3) {
144  ["date"]=>
145  string(26) "2001-11-29 %d:%d:%d.%d"
146  ["timezone_type"]=>
147  int(3)
148  ["timezone"]=>
149  string(%d) "%s"
150}
151array(4) {
152  ["warning_count"]=>
153  int(0)
154  ["warnings"]=>
155  array(0) {
156  }
157  ["error_count"]=>
158  int(0)
159  ["errors"]=>
160  array(0) {
161  }
162}
163