php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #29879 strtotime() should return false instead of -1 on failure
Submitted: 2004-08-29 00:50 UTC Modified: 2005-08-11 20:04 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: info at peter-thomassen dot de Assigned: derick (profile)
Status: Closed Package: Feature/Change Request
PHP Version: 5.1 OS: any
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: info at peter-thomassen dot de
New email:
PHP Version: OS:

 

 [2004-08-29 00:50 UTC] info at peter-thomassen dot de
Description:
------------
If an invalid time is specified, strtotime() returns -1. 
 
Because -1 is ambiguous (it could also mean 1969-12-31 
23:59:59 UTC), I request to return (bool)false on failure. 
 
BTW: 
http://www.gnu.org/software/tar/manual/html_chapter/tar_7.html#SEC117 
which is mentioned in the docs allows a number preceded by 
an '@' for the time argument to represent seconds since 
the epoch. This results in an error -- shall I report 
another bug for that? 
 
Thanks! 

Reproduce code:
---------------
<?php
var_dump(strtotime('invalid'));
?>

Expected result:
----------------
bool(false) 

Actual result:
--------------
int(-1) 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-08-29 19:01 UTC] iliaa@php.net
This change would break backwards compatibility. 
 [2004-08-29 20:15 UTC] info at peter-thomassen dot de
That's right, but I think -- since PHP5 is not that 
established to avoid any minor changes -- you can keep the 
old behaviour if zend.ze1_compatibility_mode is set to On 
and otherwise use more meaningful return values, can't 
you? 
 
I find it kind of sad if there wouldn't be any possibility 
to do proper date calculations, but another would be 
overkill ...
 [2004-08-30 08:17 UTC] derick@php.net
This is going to be changed for 5.1, which will have new datetime parse/handling stuff.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Dec 27 14:00:02 2025 UTC