php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #69685 gmmktime() does not return boolean false on error
Submitted: 2015-05-21 19:16 UTC Modified: 2022-05-13 14:51 UTC
Votes:2
Avg. Score:3.5 ± 0.5
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: alexander dot schuch+php at dezem dot de Assigned:
Status: Wont fix Package: Date/time related
PHP Version: 5.4.41 OS:
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: alexander dot schuch+php at dezem dot de
New email:
PHP Version: OS:

 

 [2015-05-21 19:16 UTC] alexander dot schuch+php at dezem dot de
Description:
------------
---
From manual page: http://www.php.net/function.gmmktime
---
The documentation of mktime() says for the return value "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)."

However, gmmktime() only ever returns an integer as of documentation.

I checked the PHP source code.

https://github.com/php/php-src/blob/c2ef8a9acc7977d07a9a92b07352cdefa7c4b9a5/ext/date/php_date.c#L1572

mktime() and gmmktime() both use the same internal function php_mktime().

https://github.com/php/php-src/blob/c2ef8a9acc7977d07a9a92b07352cdefa7c4b9a5/ext/date/php_date.c#L1491

This one in all cases returns false on invalid parameters.

The only way for gmmktime()/php_mktime() to fail is in timelib_date_to_int():

https://github.com/php/php-src/blob/f179852f838c1d88cb39097b9557b7d2ba8e5755/ext/date/lib/timelib.c#L186

However, I do not properly understand the difference between timelib_long and timelib_sll:

https://github.com/php/php-src/blob/f179852f838c1d88cb39097b9557b7d2ba8e5755/ext/date/lib/timelib_structs.h#L144

So, when actually can gmmktime() fail in case the arguments are correct or, does it return any errors?

Test script:
---------------
http://3v4l.org/2esJM

<?php
var_dump(PHP_INT_MAX);
var_dump(gmmktime(0,0,0,1,1,PHP_INT_MAX));
?>

Expected result:
----------------
I wish:

- The function should return an error in case of integer overflows or underflows (proleptic Gregorian calender is assumed).

Issues, depending on classification of documentation bug or implementation bug:

- mktime() and gmmktime() should return the same "kind of data". So only integer, or integer or false.
- Documentation of return value of mktime() and gmmktime() should be the same.
- Documentation should mention that errors are/are not detected, so either the returned timestamp is "random" (single or multiple overflows) or an error is indicated.

Actual result:
--------------
Output for 5.2.6 - 5.6.9, php7@20140507 - 20150501
    int(9223372036854775807)
    int(-62198793216) 

Output for 5.1.3 - 5.2.5
    int(9223372036854775807)
    bool(false) 

Output for 5.1.0 - 5.1.2
    int(9223372036854775807)
    Process exited with code 137.

Output for 4.4.0 - 4.4.9, 5.0.5
    int(9223372036854775807)
    int(-62198755200) 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-05-21 19:19 UTC] aharvey@php.net
-Status: Open +Status: Wont fix
 [2015-05-21 19:19 UTC] aharvey@php.net
We generally don't document on each page that invalid parameters result in false being returned: this is a normal expectation for internal functions.
 [2015-05-21 19:26 UTC] alexander dot schuch+php at dezem dot de
Why does mktime() document a possible return code of false in case of an error, while gmmktime() does not? When can mktime() fail besides invalid arguments compared to gmmktime()?

This should be documented.

The changelog documents changes in is_dst parameter in PHP 5.1. But it does not document changes in the return code. PHP 5.1.3 - 5.2.5 returns false *with valid parameters*. Later versions seem to always return an integer.

This should be documented.
 [2015-05-21 19:32 UTC] alexander dot schuch+php at dezem dot de
How can I reopen this issue? The comment given by aharvey@php.net is not related to fixing the documentation of the return code when valid and complete arguments are given.
 [2015-05-22 14:47 UTC] cmb@php.net
-Status: Wont fix +Status: Re-Opened
 [2017-01-28 17:20 UTC] cmb@php.net
-Package: Documentation problem +Package: Date/time related
 [2022-05-13 14:51 UTC] derick@php.net
-Status: Re-Opened +Status: Wont fix
 [2022-05-13 14:51 UTC] derick@php.net
I'm closing this, as mktime and gmmktime should be considered legacy APIs. If you feel strongly about this, feel free to open a ticket at https://github.com/php/php-src/issues.
 [2022-05-16 16:56 UTC] alexander dot schuch+php at dezem dot de
gmmktime()
Returns a int Unix timestamp on success, or false on failure.

mktime()
mktime() returns the Unix timestamp of the arguments given. If the arguments are invalid, the function returns false.

This means that mktime() can only return FALSE in case of invalid arguments whereas gmmktime() can also return FALSE in case of failure, like integer overflow - or what does 'failure' mean?

For mktime() the returned timestamp needs to be a signed 32 bit value. I think the most commonly used systems today are 64 bit system, but I am not sure about time_t.

For gmmktime() the year can be any integer. I guess because failure will be indicated by FALSE. But 3v4l does not agree here.

The manual does not indicate that either of the function is legacy. What is the replacement functionality then?
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Fri Aug 19 02:03:36 2022 UTC