php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33511 Re-post of #30545 strototime() returns -1 on @timestamp
Submitted: 2005-06-30 01:50 UTC Modified: 2005-06-30 17:54 UTC
From: dfdugal at spyderhost dot net Assigned:
Status: Closed Package: Date/time related
PHP Version: 5.0.4 OS: 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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: dfdugal at spyderhost dot net
New email:
PHP Version: OS:

 

 [2005-06-30 01:50 UTC] dfdugal at spyderhost dot net
Description:
------------
Found existing "Won't Fix" bug report for version 4.3.9:
#30545 strototime() returns -1 on @timestamp

Would like to petition that this gets another look in 5.x.
derick@php.net asked...
"What's the point of doing this in the first place?"

I can think of a couple;
1) To support the specification as documented and published.
2) It's a time-consuming "gotcha" when you run into it, especially since the docs state different behavior.
3) in an OO API, I may not know how the date is coming in, but want to support the widest variety of possible values. 
4) One could then use strtotime() to validate a timestamp?

The third issue is the one that got me. I wrote a Date Object (that used and wrappered many of php's date functions) that I could use in an OO framework. The constructor accepts a timestamp or any valid strtotime() input as a constructor arguement.

This allows me to do something like the following to create copies/clones, without "loosing time"
$d1 = new Date();
$d2 = new Date($d1->getTimestamp());

My initial code passed the input to strtotime() and threw an Exception if there was a problem. For the current code, I wrote a workaround, but agree with the previous post that this is a legitimate bug, primarily because it diverges from stated/documented behavior.


Reproduce code:
---------------
$timestamp = time();
$strtime = strtotime('@'.$timestamp);
echo $strtime;
if($timestamp == $strtime){
   echo 'strtotime accepts a timestamp';
}

Expected result:
----------------
{a legitimate timestamp}
strtotime accepts a timestamp

Actual result:
--------------
-1 (or FALSE using 5.1.x)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-06-30 09:10 UTC] derick@php.net
Did you test it with PHP 5.1.0dev? It works just fine here:

derick@kossu:/dat/dev/php/php-5.1dev$ sapi/cli/php
<?php
$timestamp = time();
$strtime = strtotime('@'.$timestamp);
echo $strtime;
if($timestamp == $strtime){
   echo 'strtotime accepts a timestamp';
}
?>
1120115382strtotime accepts a timestamp

And we won't add new features to PHP 4.x.
 [2005-06-30 17:54 UTC] dfdugal at spyderhost dot net
Confirmed fixed in php-5.1.0b2
Thanks!
 - Dan
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jun 01 08:01:32 2024 UTC