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