xref: /PHP-5.6/ext/date/tests/date_variation1.phpt (revision a2e47734)
1--TEST--
2Test date() function : usage variation - Passing unexpected values to first argument $format.
3--FILE--
4<?php
5/* Prototype  : string date  ( string $format  [, int $timestamp  ] )
6 * Description: Format a local time/date.
7 * Source code: ext/date/php_date.c
8 */
9
10echo "*** Testing date() : usage variation -  unexpected values to first argument \$format***\n";
11
12//Set the default time zone
13date_default_timezone_set("Europe/London");
14
15//get an unset variable
16$unset_var = 10;
17unset ($unset_var);
18
19// define some classes
20class classWithToString
21{
22	public function __toString() {
23		return "Class A object";
24	}
25}
26
27class classWithoutToString
28{
29}
30
31// heredoc string
32$heredoc = <<<EOT
33hello world
34EOT;
35
36// add arrays
37$index_array = array (1, 2, 3);
38$assoc_array = array ('one' => 1, 'two' => 2);
39
40// resource
41$file_handle = fopen(__FILE__, 'r');
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      // resource
94      'resource' => $file_handle
95);
96
97$timestamp = mktime(10, 44, 30, 2, 27, 2009);
98
99foreach($inputs as $variation =>$format) {
100      echo "\n-- $variation --\n";
101      var_dump( date($format, $timestamp) );
102};
103
104// closing the resource
105fclose( $file_handle );
106
107?>
108===DONE===
109--EXPECTF--
110*** Testing date() : usage variation -  unexpected values to first argument $format***
111
112-- int 0 --
113string(1) "0"
114
115-- int 1 --
116string(1) "1"
117
118-- int 12345 --
119string(5) "12345"
120
121-- int -12345 --
122string(6) "-12345"
123
124-- float 10.5 --
125string(4) "10.5"
126
127-- float -10.5 --
128string(5) "-10.5"
129
130-- float .5 --
131string(3) "0.5"
132
133-- empty array --
134
135Warning: date() expects parameter 1 to be string, array given in %s on line %d
136bool(false)
137
138-- int indexed array --
139
140Warning: date() expects parameter 1 to be string, array given in %s on line %d
141bool(false)
142
143-- associative array --
144
145Warning: date() expects parameter 1 to be string, array given in %s on line %d
146bool(false)
147
148-- nested arrays --
149
150Warning: date() expects parameter 1 to be string, array given in %s on line %d
151bool(false)
152
153-- uppercase NULL --
154string(0) ""
155
156-- lowercase null --
157string(0) ""
158
159-- lowercase true --
160string(1) "1"
161
162-- lowercase false --
163string(0) ""
164
165-- uppercase TRUE --
166string(1) "1"
167
168-- uppercase FALSE --
169string(0) ""
170
171-- empty string DQ --
172string(0) ""
173
174-- empty string SQ --
175string(0) ""
176
177-- string DQ --
178string(40) "3028Fri, 27 Feb 2009 10:44:30 +000044210"
179
180-- string SQ --
181string(40) "3028Fri, 27 Feb 2009 10:44:30 +000044210"
182
183-- mixed case string --
184string(40) "30GMTFri, 27 Feb 2009 10:44:30 +00000210"
185
186-- heredoc --
187string(76) "10Europe/LondonFridayFriday2009 52009Fri, 27 Feb 2009 10:44:30 +0000Friday27"
188
189-- instance of classWithToString --
190string(64) "CFridayam3030 AM 2009b27Europe/London2009-02-27T10:44:30+00:0028"
191
192-- instance of classWithoutToString --
193
194Warning: date() expects parameter 1 to be string, object given in %s on line %d
195bool(false)
196
197-- undefined var --
198string(0) ""
199
200-- unset var --
201string(0) ""
202
203-- resource --
204
205Warning: date() expects parameter 1 to be string, resource given in %s on line %d
206bool(false)
207===DONE===
208
209