1--TEST--
2Test gmdate() function : usage variation - Passing unexpected values to timestamp argument.
3--FILE--
4<?php
5/* Prototype  : string gmdate(string format [, long timestamp])
6 * Description: Format a GMT date/time
7 * Source code: ext/date/php_date.c
8 * Alias to functions:
9 */
10
11echo "*** Testing gmdate() : usage variation ***\n";
12
13
14// Initialise all required variables
15date_default_timezone_set('UTC');
16$format = DATE_ISO8601;
17
18//get an unset variable
19$unset_var = 10;
20unset ($unset_var);
21
22// define some classes
23class classWithToString
24{
25	public function __toString() {
26		return "Class A object";
27	}
28}
29
30class classWithoutToString
31{
32}
33
34// heredoc string
35$heredoc = <<<EOT
36hello world
37EOT;
38
39// add arrays
40$index_array = array (1, 2, 3);
41$assoc_array = array ('one' => 1, 'two' => 2);
42
43//array of values to iterate over
44$inputs = array(
45
46      // int data
47      'int 0' => 0,
48      'int 1' => 1,
49      'int 12345' => 12345,
50      'int -12345' => -12345,
51
52      // float data
53      'float 10.5' => 10.5,
54      'float -10.5' => -10.5,
55      'float .5' => .5,
56
57      // array data
58      'empty array' => array(),
59      'int indexed array' => $index_array,
60      'associative array' => $assoc_array,
61      'nested arrays' => array('foo', $index_array, $assoc_array),
62
63      // null data
64      'uppercase NULL' => NULL,
65      'lowercase null' => null,
66
67      // boolean data
68      'lowercase true' => true,
69      'lowercase false' =>false,
70      'uppercase TRUE' =>TRUE,
71      'uppercase FALSE' =>FALSE,
72
73      // empty data
74      'empty string DQ' => "",
75      'empty string SQ' => '',
76
77      // string data
78      'string DQ' => "string",
79      'string SQ' => 'string',
80      'mixed case string' => "sTrInG",
81      'heredoc' => $heredoc,
82
83      // object data
84      'instance of classWithToString' => new classWithToString(),
85      'instance of classWithoutToString' => new classWithoutToString(),
86
87      // undefined data
88      'undefined var' => @$undefined_var,
89
90      // unset data
91      'unset var' => @$unset_var,
92);
93
94// loop through each element of the array for timestamp
95
96foreach($inputs as $key =>$value) {
97      echo "\n--$key--\n";
98      var_dump( gmdate($format, $value) );
99};
100
101?>
102===DONE===
103--EXPECTF--
104*** Testing gmdate() : usage variation ***
105
106--int 0--
107string(24) "1970-01-01T00:00:00+0000"
108
109--int 1--
110string(24) "1970-01-01T00:00:01+0000"
111
112--int 12345--
113string(24) "1970-01-01T03:25:45+0000"
114
115--int -12345--
116string(24) "1969-12-31T20:34:15+0000"
117
118--float 10.5--
119string(24) "1970-01-01T00:00:10+0000"
120
121--float -10.5--
122string(24) "1969-12-31T23:59:50+0000"
123
124--float .5--
125string(24) "1970-01-01T00:00:00+0000"
126
127--empty array--
128
129Warning: gmdate() expects parameter 2 to be long, array given in %s on line %d
130bool(false)
131
132--int indexed array--
133
134Warning: gmdate() expects parameter 2 to be long, array given in %s on line %d
135bool(false)
136
137--associative array--
138
139Warning: gmdate() expects parameter 2 to be long, array given in %s on line %d
140bool(false)
141
142--nested arrays--
143
144Warning: gmdate() expects parameter 2 to be long, array given in %s on line %d
145bool(false)
146
147--uppercase NULL--
148string(24) "1970-01-01T00:00:00+0000"
149
150--lowercase null--
151string(24) "1970-01-01T00:00:00+0000"
152
153--lowercase true--
154string(24) "1970-01-01T00:00:01+0000"
155
156--lowercase false--
157string(24) "1970-01-01T00:00:00+0000"
158
159--uppercase TRUE--
160string(24) "1970-01-01T00:00:01+0000"
161
162--uppercase FALSE--
163string(24) "1970-01-01T00:00:00+0000"
164
165--empty string DQ--
166
167Warning: gmdate() expects parameter 2 to be long, string given in %s on line %d
168bool(false)
169
170--empty string SQ--
171
172Warning: gmdate() expects parameter 2 to be long, string given in %s on line %d
173bool(false)
174
175--string DQ--
176
177Warning: gmdate() expects parameter 2 to be long, string given in %s on line %d
178bool(false)
179
180--string SQ--
181
182Warning: gmdate() expects parameter 2 to be long, string given in %s on line %d
183bool(false)
184
185--mixed case string--
186
187Warning: gmdate() expects parameter 2 to be long, string given in %s on line %d
188bool(false)
189
190--heredoc--
191
192Warning: gmdate() expects parameter 2 to be long, string given in %s on line %d
193bool(false)
194
195--instance of classWithToString--
196
197Warning: gmdate() expects parameter 2 to be long, object given in %s on line %d
198bool(false)
199
200--instance of classWithoutToString--
201
202Warning: gmdate() expects parameter 2 to be long, object given in %s on line %d
203bool(false)
204
205--undefined var--
206string(24) "1970-01-01T00:00:00+0000"
207
208--unset var--
209string(24) "1970-01-01T00:00:00+0000"
210===DONE===
211