1--TEST--
2Test strftime() function : usage variation - Passing unexpected values to first argument 'format'.
3--FILE--
4<?php
5/* Prototype  : string strftime(string format [, int timestamp])
6 * Description: Format a local time/date according to locale settings
7 * Source code: ext/date/php_date.c
8 * Alias to functions:
9 */
10
11echo "*** Testing strftime() : usage variation ***\n";
12
13date_default_timezone_set("Asia/Calcutta");
14
15// Initialise function arguments not being substituted (if any)
16$timestamp = 10;
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 12.3456789000e10' => 12.3456789000e10,
56      'float -12.3456789000e10' => -12.3456789000e10,
57      'float .5' => .5,
58
59      // array data
60      'empty array' => array(),
61      'int indexed array' => $index_array,
62      'associative array' => $assoc_array,
63      'nested arrays' => array('foo', $index_array, $assoc_array),
64
65      // null data
66      'uppercase NULL' => NULL,
67      'lowercase null' => null,
68
69      // boolean data
70      'lowercase true' => true,
71      'lowercase false' =>false,
72      'uppercase TRUE' =>TRUE,
73      'uppercase FALSE' =>FALSE,
74
75      // empty data
76      'empty string DQ' => "",
77      'empty string SQ' => '',
78
79      // object data
80      'instance of classWithToString' => new classWithToString(),
81      'instance of classWithoutToString' => new classWithoutToString(),
82
83      // undefined data
84      'undefined var' => @$undefined_var,
85
86      // unset data
87      'unset var' => @$unset_var,
88);
89
90// loop through each element of the array for format
91
92foreach($inputs as $key =>$value) {
93      echo "\n--$key--\n";
94      var_dump( strftime($value) );
95      var_dump( strftime($value, $timestamp) );
96};
97
98?>
99===DONE===
100--EXPECTF--
101*** Testing strftime() : usage variation ***
102
103--int 0--
104string(1) "0"
105string(1) "0"
106
107--int 1--
108string(1) "1"
109string(1) "1"
110
111--int 12345--
112string(5) "12345"
113string(5) "12345"
114
115--int -12345--
116string(6) "-12345"
117string(6) "-12345"
118
119--float 10.5--
120string(4) "10.5"
121string(4) "10.5"
122
123--float -10.5--
124string(5) "-10.5"
125string(5) "-10.5"
126
127--float 12.3456789000e10--
128string(12) "123456789000"
129string(12) "123456789000"
130
131--float -12.3456789000e10--
132string(13) "-123456789000"
133string(13) "-123456789000"
134
135--float .5--
136string(3) "0.5"
137string(3) "0.5"
138
139--empty array--
140
141Warning: strftime() expects parameter 1 to be string, array given in %s on line %d
142bool(false)
143
144Warning: strftime() expects parameter 1 to be string, array given in %s on line %d
145bool(false)
146
147--int indexed array--
148
149Warning: strftime() expects parameter 1 to be string, array given in %s on line %d
150bool(false)
151
152Warning: strftime() expects parameter 1 to be string, array given in %s on line %d
153bool(false)
154
155--associative array--
156
157Warning: strftime() expects parameter 1 to be string, array given in %s on line %d
158bool(false)
159
160Warning: strftime() expects parameter 1 to be string, array given in %s on line %d
161bool(false)
162
163--nested arrays--
164
165Warning: strftime() expects parameter 1 to be string, array given in %s on line %d
166bool(false)
167
168Warning: strftime() expects parameter 1 to be string, array given in %s on line %d
169bool(false)
170
171--uppercase NULL--
172bool(false)
173bool(false)
174
175--lowercase null--
176bool(false)
177bool(false)
178
179--lowercase true--
180string(1) "1"
181string(1) "1"
182
183--lowercase false--
184bool(false)
185bool(false)
186
187--uppercase TRUE--
188string(1) "1"
189string(1) "1"
190
191--uppercase FALSE--
192bool(false)
193bool(false)
194
195--empty string DQ--
196bool(false)
197bool(false)
198
199--empty string SQ--
200bool(false)
201bool(false)
202
203--instance of classWithToString--
204string(14) "Class A object"
205string(14) "Class A object"
206
207--instance of classWithoutToString--
208
209Warning: strftime() expects parameter 1 to be string, object given in %s on line %d
210bool(false)
211
212Warning: strftime() expects parameter 1 to be string, object given in %s on line %d
213bool(false)
214
215--undefined var--
216bool(false)
217bool(false)
218
219--unset var--
220bool(false)
221bool(false)
222===DONE===
223