|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #47806 mktime should return -1 or false on invalid args, but returns 943912800
Submitted: 2009-03-27 12:25 UTC Modified: 2015-05-02 11:56 UTC
Avg. Score:4.4 ± 0.8
Reproduced:5 of 5 (100.0%)
Same Version:3 (60.0%)
Same OS:2 (40.0%)
From: glen at delfi dot ee Assigned: cmb (profile)
Status: Closed Package: Date/time related
PHP Version: 5.2.9 OS: PLD Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: glen at delfi dot ee
New email:
PHP Version: OS:


 [2009-03-27 12:25 UTC] glen at delfi dot ee

"mktime() returns the Unix timestamp of the arguments given. If the 
arguments are invalid, the function returns FALSE (before PHP 5.1 it 
returned -1)."

but it returns "Tue Nov 30 00:00:00 1999 +0200" instead when invalid 
input like null (or undefined) is used:

php -r 'echo mktime(0, 0, 0, null, null, null), "\n";'

ok, i understand if all params are 0, then it would make sense:

"The number of the year, may be a two or four digit value, with 
values between 0-69 mapping to 2000-2069 and 70-100 to 1970-2000. On 
systems where time_t is a 32bit signed integer, as most common 
today, the valid range for year is somewhere between 1901 and 2038. 
However, before PHP 5.1.0 this range was limited from 1970 to 2038 
on some systems (e.g. Windows)."

Year as 0 is 2000,
Month 0 is calculated as 12 of the last year, thus it gets December 
and 0 December is 30 November

please make using undefined variables and nulls being invalid input 
(so that you must cast to int, to treat empty input as 0):

php -r 'echo mktime(0, 0, 0, (int )$_GET['day'], 
(int )$_GET['month'], (int )$_GET['year']), "\n";'


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-23 21:18 UTC]
-Package: Feature/Change Request +Package: Date/time related
 [2015-05-01 19:48 UTC]
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2015-05-01 19:48 UTC]
Juggling NULL to 0 when an integer is expected is normal behavior
for PHP, e.g.

  echo cos(null); // 1
Just changing a single function in this respect would be
confusing, and too much of a BC break, in my opinion. However, PHP
7 is going to give the ability to switch to a stricter mode[1]
Then passing NULL where an integer is expected will produce
E_RECOVERABLE_ERROR. You could catch the Exception and wrap the
code in a small function; a simplified example:

Do you deem that sufficient?

[1] <>
 [2015-05-02 08:40 UTC] glen at delfi dot ee
-Status: Feedback +Status: Assigned
 [2015-05-02 08:40 UTC] glen at delfi dot ee
it's a late reply, but okay, yes! :)
 [2015-05-02 11:56 UTC]
-Status: Assigned +Status: Closed
 [2015-05-02 11:56 UTC]
> it's a late reply

Sorry. However, better late then never. :)

> but okay, yes! :)

Fine. Closing.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jul 22 04:01:29 2024 UTC