php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78509 Calling time() with parameter(s) returns NULL
Submitted: 2019-09-07 12:25 UTC Modified: 2019-09-07 18:19 UTC
From: gvre at gvre dot gr Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 7.3 OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: gvre at gvre dot gr
New email:
PHP Version: OS:

 

 [2019-09-07 12:25 UTC] gvre at gvre dot gr
Description:
------------
Calling the "time()" function with a parameter works fine in PHP <= 7.2.x and returns an int. In PHP 7.3, it returns NULL and produces a "Warning: time() expects exactly 0 parameters, 1 given" message instead.

https://3v4l.org/OT21N
https://github.com/php/php-src/blob/php-7.3.0/ext/date/php_date.c#L1775

I know that passing a parameter to time() is wrong, but I think it could produce a warning and return the value in PHP 7.3 (and 7.4 maybe), since it works fine in 7.2 and is common in C to call it that way. 
I did not find anything related to deprecation pages, so it may be useful to document this behavior as deprecated in case you decide to keep it as is.

Test script:
---------------
<?php
var_dump(time(null));

Expected result:
----------------
The current Unix timestamp.

Actual result:
--------------
NULL

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-09-07 15:04 UTC] girgias@php.net
-Status: Open +Status: Not a bug -Operating System: Linux +Operating System: -PHP Version: 7.3Git-2019-09-07 (Git) +PHP Version: 7.3
 [2019-09-07 15:04 UTC] girgias@php.net
This is not a bug on PHP's side, moreover this will throw an ArgumentCountError as of PHP 8. [1]

[1] https://wiki.php.net/rfc/consistent_type_errors
 [2019-09-07 18:19 UTC] gvre at gvre dot gr
It is very good that PHP 8 will be throwing an ArgumentCountError in such cases, but the change introduced in 7.3 breaks code that works in all previous versions (4.3.0 - 7.2.22). Ideally, 7.3 should be creating a warning and a later version be stricter if needed. It would also be helpful for people who want to upgrade to be aware of that change.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 19 10:01:28 2024 UTC