reference/datetime/functions/mktime.xml
349e3c6502e0bbeb15aef2b4a4a25f3f5e10fbfe
...
...
@@ -9,14 +9,13 @@
9
9
<refsect1 role="description">
10
10
&reftitle.description;
11
11
<methodsynopsis>
12
-
<type>int</type><methodname>mktime</methodname>
13
-
<methodparam choice="opt"><type>int</type><parameter>hour</parameter><initializer>date("H")</initializer></methodparam>
14
-
<methodparam choice="opt"><type>int</type><parameter>minute</parameter><initializer>date("i")</initializer></methodparam>
15
-
<methodparam choice="opt"><type>int</type><parameter>second</parameter><initializer>date("s")</initializer></methodparam>
16
-
<methodparam choice="opt"><type>int</type><parameter>month</parameter><initializer>date("n")</initializer></methodparam>
17
-
<methodparam choice="opt"><type>int</type><parameter>day</parameter><initializer>date("j")</initializer></methodparam>
18
-
<methodparam choice="opt"><type>int</type><parameter>year</parameter><initializer>date("Y")</initializer></methodparam>
19
-
<methodparam choice="opt"><type>int</type><parameter>is_dst</parameter><initializer>-1</initializer></methodparam>
12
+
<type class="union"><type>int</type><type>false</type></type><methodname>mktime</methodname>
13
+
<methodparam><type>int</type><parameter>hour</parameter></methodparam>
14
+
<methodparam choice="opt"><type class="union"><type>int</type><type>null</type></type><parameter>minute</parameter><initializer>&null;</initializer></methodparam>
15
+
<methodparam choice="opt"><type class="union"><type>int</type><type>null</type></type><parameter>second</parameter><initializer>&null;</initializer></methodparam>
16
+
<methodparam choice="opt"><type class="union"><type>int</type><type>null</type></type><parameter>month</parameter><initializer>&null;</initializer></methodparam>
17
+
<methodparam choice="opt"><type class="union"><type>int</type><type>null</type></type><parameter>day</parameter><initializer>&null;</initializer></methodparam>
18
+
<methodparam choice="opt"><type class="union"><type>int</type><type>null</type></type><parameter>year</parameter><initializer>&null;</initializer></methodparam>
20
19
</methodsynopsis>
21
20
<para>
22
21
Returns the Unix timestamp corresponding to the arguments
...
...
@@ -25,21 +24,24 @@
25
24
specified.
26
25
</para>
27
26
<para>
28
-
Arguments may be left out in order from right to left; any
29
-
arguments thus omitted will be set to the current value according
27
+
Any optional
28
+
arguments omitted or &null; will be set to the current value according
30
29
to the local date and time.
31
30
</para>
32
-
</refsect1>
33
-

34
-
<refsect1 role="notes">
35
-
&reftitle.notes;
36
-
<note>
31
+
<warning>
37
32
<para>
38
-
As of PHP 5.1, when called with no arguments, <function>mktime</function>
39
-
throws an <constant>E_STRICT</constant> notice: use the
40
-
<function>time</function> function instead.
33
+
Please note that the ordering of arguments is in an odd order:
34
+
<parameter>month</parameter>, <parameter>day</parameter>,
35
+
<parameter>year</parameter>, and not in the more reasonable order of
36
+
<parameter>year</parameter>, <parameter>month</parameter>,
37
+
<parameter>day</parameter>.
41
38
</para>
42
-
</note>
39
+
</warning>
40
+
<simpara>
41
+
Calling <function>mktime</function> without arguments is not supported,
42
+
and will result in an <classname>ArgumentCountError</classname>.
43
+
<function>time</function> can be used to get the current timestamp.
44
+
</simpara>
43
45
</refsect1>
44
46

45
47
<refsect1 role="parameters">
...
...
@@ -107,37 +109,8 @@
107
109
with values between 0-69 mapping to 2000-2069 and 70-100 to
108
110
1970-2000. On systems where time_t is a 32bit signed integer, as
109
111
most common today, the valid range for <parameter>year</parameter>
110
-
is somewhere between 1901 and 2038. However, before PHP 5.1.0 this
111
-
range was limited from 1970 to 2038 on some systems (e.g. Windows).
112
-
</para>
113
-
</listitem>
114
-
</varlistentry>
115
-
<varlistentry>
116
-
<term><parameter>is_dst</parameter></term>
117
-
<listitem>
118
-
<para>
119
-
This parameter can be set to 1 if the time is during daylight savings time (DST),
120
-
0 if it is not, or -1 (the default) if it is unknown whether the time is within
121
-
daylight savings time or not. If it's unknown, PHP tries to figure it out itself.
122
-
This can cause unexpected (but not incorrect) results.
123
-
Some times are invalid if DST is enabled on the system PHP is running on or
124
-
<parameter>is_dst</parameter> is set to 1. If DST is enabled in e.g. 2:00, all times
125
-
between 2:00 and 3:00 are invalid and <function>mktime</function> returns an undefined
126
-
(usually negative) value.
127
-
Some systems (e.g. Solaris 8) enable DST at midnight so time 0:30 of the day when DST
128
-
is enabled is evaluated as 23:30 of the previous day.
112
+
is somewhere between 1901 and 2038.
129
113
</para>
130
-
<note>
131
-
<para>
132
-
As of PHP 5.1.0, this parameter became deprecated. As a result, the
133
-
new timezone handling features should be used instead.
134
-
</para>
135
-
</note>
136
-
<note>
137
-
<para>
138
-
This parameter has been removed in PHP 7.0.0.
139
-
</para>
140
-
</note>
141
114
</listitem>
142
115
</varlistentry>
143
116
</variablelist>
...
...
@@ -149,17 +122,10 @@
149
122
&reftitle.returnvalues;
150
123
<para>
151
124
<function>mktime</function> returns the Unix timestamp of the arguments
152
-
given.
153
-
If the arguments are invalid, the function returns &false; (before PHP 5.1
154
-
it returned <literal>-1</literal>).
125
+
given, or &false; if the timestamp doesn't fit in a PHP integer.
155
126
</para>
156
127
</refsect1>
157
128

158
-
<refsect1 role="errors">
159
-
&reftitle.errors;
160
-
&date.timezone.errors.description;
161
-
</refsect1>
162
-

163
129
<refsect1 role="changelog">
164
130
&reftitle.changelog;
165
131
<para>
...
...
@@ -173,39 +139,19 @@
173
139
</thead>
174
140
<tbody>
175
141
<row>
176
-
<entry>7.0.0</entry>
177
-
<entry>
178
-
<parameter>is_dst</parameter> parameter has been removed.
179
-
</entry>
180
-
</row>
181
-
<row>
182
-
<entry>5.3.0</entry>
142
+
<entry>8.0.0</entry>
183
143
<entry>
184
-
<function>mktime</function> now throws <constant>E_DEPRECATED</constant> notice
185
-
if the <parameter>is_dst</parameter> parameter is used.
144
+
<parameter>hour</parameter> is no longer optional. If you need a Unix
145
+
timestamp, use <function>time</function>.
186
146
</entry>
187
147
</row>
188
148
<row>
189
-
<entry>5.1.0</entry>
149
+
<entry>8.0.0</entry>
190
150
<entry>
191
-
The <parameter>is_dst</parameter> parameter became deprecated.
192
-
Made the function return &false; on error, instead of
193
-
<literal>-1</literal>.
194
-
Fixed the function to accept the year, month and day to be all passed
195
-
as zero.
151
+
<parameter>minute</parameter>, <parameter>second</parameter>, <parameter>month</parameter>,
152
+
<parameter>day</parameter> and <parameter>year</parameter> are nullable now.
196
153
</entry>
197
154
</row>
198
-
<row>
199
-
<entry>5.1.0</entry>
200
-
<entry>
201
-
When called with no arguments, <function>mktime</function> throws
202
-
<constant>E_STRICT</constant> notice. Use the
203
-
<function>time</function> function instead.
204
-
</entry>
205
-
</row>
206
-

207
-
&date.timezone.errors.changelog;
208
-

209
155
</tbody>
210
156
</tgroup>
211
157
</informaltable>
...
...
@@ -220,7 +166,7 @@
220
166
<programlisting role="php">
221
167
<![CDATA[
222
168
<?php
223
-
// Set the default timezone to use. Available as of PHP 5.1
169
+
// Set the default timezone to use.
224
170
date_default_timezone_set('UTC');
225
171

226
172
// Prints: July 1, 2000 is on a Saturday
...
...
@@ -265,10 +211,13 @@ echo date("M-d-Y", mktime(0, 0, 0, 1, 1, 98));
265
211
<programlisting role="php">
266
212
<![CDATA[
267
213
<?php
214
+

268
215
$lastday = mktime(0, 0, 0, 3, 0, 2000);
269
-
echo strftime("Last day in Feb 2000 is: %d", $lastday);
216
+
echo 'Last day in Feb 2000 is: ', date('d', $lastday);
217
+

270
218
$lastday = mktime(0, 0, 0, 4, -31, 2000);
271
-
echo strftime("Last day in Feb 2000 is: %d", $lastday);
219
+
echo 'Last day in Feb 2000 is: ', date('d', $lastday);
220
+

272
221
?>
273
222
]]>
274
223
</programlisting>
...
...
@@ -276,21 +225,11 @@ echo strftime("Last day in Feb 2000 is: %d", $lastday);
276
225
</para>
277
226
</refsect1>
278
227

279
-
<refsect1 role="notes">
280
-
&reftitle.notes;
281
-
<caution>
282
-
<para>
283
-
Before PHP 5.1.0, negative timestamps were not supported under any known
284
-
version of Windows and some other systems as well. Therefore the range of
285
-
valid years was limited to 1970 through 2038.
286
-
</para>
287
-
</caution>
288
-
</refsect1>
289
-

290
228
<refsect1 role="seealso">
291
229
&reftitle.seealso;
292
230
<para>
293
231
<simplelist>
232
+
<member>The <classname>DateTimeImmutable</classname> class</member>
294
233
<member><function>checkdate</function></member>
295
234
<member><function>gmmktime</function></member>
296
235
<member><function>date</function></member>
...
...
@@ -299,7 +238,6 @@ echo strftime("Last day in Feb 2000 is: %d", $lastday);
299
238
</para>
300
239
</refsect1>
301
240
</refentry>
302
-

303
241
<!-- Keep this comment at the end of the file
304
242
Local variables:
305
243
mode: sgml
306
244