1--TEST--
2Test date_create() function : usage variation - Passing unexpected values to first argument $time.
3--FILE--
4<?php
5/* Prototype  : DateTime date_create  ([ string $time  [, DateTimeZone $timezone  ]] )
6 * Description: Returns new DateTime object
7 * Source code: ext/date/php_date.c
8 * Alias to functions: DateTime::__construct
9 */
10
11echo "*** Testing date_create() : usage variation -  unexpected values to first argument \$time***\n";
12
13//Set the default time zone
14date_default_timezone_set("Europe/London");
15
16//get an unset variable
17$unset_var = 10;
18unset ($unset_var);
19
20// define some classes
21class classWithToString
22{
23	public function __toString() {
24		return "Class A object";
25	}
26}
27
28class classWithoutToString
29{
30}
31
32// heredoc string
33$heredoc = <<<EOT
34hello world
35EOT;
36
37// add arrays
38$index_array = array (1, 2, 3);
39$assoc_array = array ('one' => 1, 'two' => 2);
40
41// resource
42$file_handle = fopen(__FILE__, 'r');
43
44//array of values to iterate over
45$inputs = array(
46
47      // int data
48      'int 0' => 0,
49      'int 1' => 1,
50      'int 12345' => 12345,
51      'int -12345' => -12345,
52
53      // float data
54      'float 10.5' => 10.5,
55      'float -10.5' => -10.5,
56      'float .5' => .5,
57
58      // array data
59      'empty array' => array(),
60      'int indexed array' => $index_array,
61      'associative array' => $assoc_array,
62      'nested arrays' => array('foo', $index_array, $assoc_array),
63
64      // null data
65      'uppercase NULL' => NULL,
66      'lowercase null' => null,
67
68      // boolean data
69      'lowercase true' => true,
70      'lowercase false' =>false,
71      'uppercase TRUE' =>TRUE,
72      'uppercase FALSE' =>FALSE,
73
74      // empty data
75      'empty string DQ' => "",
76      'empty string SQ' => '',
77
78      // string data
79      'string DQ' => "string",
80      'string SQ' => 'string',
81      'mixed case string' => "sTrInG",
82      'heredoc' => $heredoc,
83
84      // object data
85      'instance of classWithToString' => new classWithToString(),
86      'instance of classWithoutToString' => new classWithoutToString(),
87
88      // undefined data
89      'undefined var' => @$undefined_var,
90
91      // unset data
92      'unset var' => @$unset_var,
93
94      // resource
95      'resource' => $file_handle
96);
97
98$timezone = new DateTimeZone("Europe/London");
99
100foreach($inputs as $variation =>$time) {
101      echo "\n-- $variation --\n";
102      var_dump( date_create($time) );
103      var_dump( date_create($time, $timezone) );
104};
105
106// closing the resource
107fclose( $file_handle);
108
109?>
110===DONE===
111--EXPECTF--
112*** Testing date_create() : usage variation -  unexpected values to first argument $time***
113
114-- int 0 --
115bool(false)
116bool(false)
117
118-- int 1 --
119bool(false)
120bool(false)
121
122-- int 12345 --
123bool(false)
124bool(false)
125
126-- int -12345 --
127bool(false)
128bool(false)
129
130-- float 10.5 --
131object(DateTime)#%d (3) {
132  ["date"]=>
133  string(26) "%s"
134  ["timezone_type"]=>
135  int(3)
136  ["timezone"]=>
137  string(13) "Europe/London"
138}
139object(DateTime)#%d (3) {
140  ["date"]=>
141  string(26) "%s"
142  ["timezone_type"]=>
143  int(3)
144  ["timezone"]=>
145  string(13) "Europe/London"
146}
147
148-- float -10.5 --
149bool(false)
150bool(false)
151
152-- float .5 --
153object(DateTime)#%d (3) {
154  ["date"]=>
155  string(26) "%s"
156  ["timezone_type"]=>
157  int(3)
158  ["timezone"]=>
159  string(13) "Europe/London"
160}
161object(DateTime)#%d (3) {
162  ["date"]=>
163  string(26) "%s"
164  ["timezone_type"]=>
165  int(3)
166  ["timezone"]=>
167  string(13) "Europe/London"
168}
169
170-- empty array --
171
172Warning: date_create() expects parameter 1 to be string, array given in %s on line %d
173bool(false)
174
175Warning: date_create() expects parameter 1 to be string, array given in %s on line %d
176bool(false)
177
178-- int indexed array --
179
180Warning: date_create() expects parameter 1 to be string, array given in %s on line %d
181bool(false)
182
183Warning: date_create() expects parameter 1 to be string, array given in %s on line %d
184bool(false)
185
186-- associative array --
187
188Warning: date_create() expects parameter 1 to be string, array given in %s on line %d
189bool(false)
190
191Warning: date_create() expects parameter 1 to be string, array given in %s on line %d
192bool(false)
193
194-- nested arrays --
195
196Warning: date_create() expects parameter 1 to be string, array given in %s on line %d
197bool(false)
198
199Warning: date_create() expects parameter 1 to be string, array given in %s on line %d
200bool(false)
201
202-- uppercase NULL --
203object(DateTime)#%d (3) {
204  ["date"]=>
205  string(26) "%s"
206  ["timezone_type"]=>
207  int(3)
208  ["timezone"]=>
209  string(13) "Europe/London"
210}
211object(DateTime)#%d (3) {
212  ["date"]=>
213  string(26) "%s"
214  ["timezone_type"]=>
215  int(3)
216  ["timezone"]=>
217  string(13) "Europe/London"
218}
219
220-- lowercase null --
221object(DateTime)#%d (3) {
222  ["date"]=>
223  string(26) "%s"
224  ["timezone_type"]=>
225  int(3)
226  ["timezone"]=>
227  string(13) "Europe/London"
228}
229object(DateTime)#%d (3) {
230  ["date"]=>
231  string(26) "%s"
232  ["timezone_type"]=>
233  int(3)
234  ["timezone"]=>
235  string(13) "Europe/London"
236}
237
238-- lowercase true --
239bool(false)
240bool(false)
241
242-- lowercase false --
243object(DateTime)#%d (3) {
244  ["date"]=>
245  string(26) "%s"
246  ["timezone_type"]=>
247  int(3)
248  ["timezone"]=>
249  string(13) "Europe/London"
250}
251object(DateTime)#%d (3) {
252  ["date"]=>
253  string(26) "%s"
254  ["timezone_type"]=>
255  int(3)
256  ["timezone"]=>
257  string(13) "Europe/London"
258}
259
260-- uppercase TRUE --
261bool(false)
262bool(false)
263
264-- uppercase FALSE --
265object(DateTime)#%d (3) {
266  ["date"]=>
267  string(26) "%s"
268  ["timezone_type"]=>
269  int(3)
270  ["timezone"]=>
271  string(13) "Europe/London"
272}
273object(DateTime)#%d (3) {
274  ["date"]=>
275  string(26) "%s"
276  ["timezone_type"]=>
277  int(3)
278  ["timezone"]=>
279  string(13) "Europe/London"
280}
281
282-- empty string DQ --
283object(DateTime)#%d (3) {
284  ["date"]=>
285  string(26) "%s"
286  ["timezone_type"]=>
287  int(3)
288  ["timezone"]=>
289  string(13) "Europe/London"
290}
291object(DateTime)#%d (3) {
292  ["date"]=>
293  string(26) "%s"
294  ["timezone_type"]=>
295  int(3)
296  ["timezone"]=>
297  string(13) "Europe/London"
298}
299
300-- empty string SQ --
301object(DateTime)#%d (3) {
302  ["date"]=>
303  string(26) "%s"
304  ["timezone_type"]=>
305  int(3)
306  ["timezone"]=>
307  string(13) "Europe/London"
308}
309object(DateTime)#%d (3) {
310  ["date"]=>
311  string(26) "%s"
312  ["timezone_type"]=>
313  int(3)
314  ["timezone"]=>
315  string(13) "Europe/London"
316}
317
318-- string DQ --
319bool(false)
320bool(false)
321
322-- string SQ --
323bool(false)
324bool(false)
325
326-- mixed case string --
327bool(false)
328bool(false)
329
330-- heredoc --
331bool(false)
332bool(false)
333
334-- instance of classWithToString --
335bool(false)
336bool(false)
337
338-- instance of classWithoutToString --
339
340Warning: date_create() expects parameter 1 to be string, object given in %s on line %d
341bool(false)
342
343Warning: date_create() expects parameter 1 to be string, object given in %s on line %d
344bool(false)
345
346-- undefined var --
347object(DateTime)#%d (3) {
348  ["date"]=>
349  string(26) "%s"
350  ["timezone_type"]=>
351  int(3)
352  ["timezone"]=>
353  string(13) "Europe/London"
354}
355object(DateTime)#%d (3) {
356  ["date"]=>
357  string(26) "%s"
358  ["timezone_type"]=>
359  int(3)
360  ["timezone"]=>
361  string(13) "Europe/London"
362}
363
364-- unset var --
365object(DateTime)#%d (3) {
366  ["date"]=>
367  string(26) "%s"
368  ["timezone_type"]=>
369  int(3)
370  ["timezone"]=>
371  string(13) "Europe/London"
372}
373object(DateTime)#%d (3) {
374  ["date"]=>
375  string(26) "%s"
376  ["timezone_type"]=>
377  int(3)
378  ["timezone"]=>
379  string(13) "Europe/London"
380}
381
382-- resource --
383
384Warning: date_create() expects parameter 1 to be string, resource given in %s on line %d
385bool(false)
386
387Warning: date_create() expects parameter 1 to be string, resource given in %s on line %d
388bool(false)
389===DONE===
390