php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65623 BC change: strtotime() returns non-false for certain integer input values
Submitted: 2013-09-05 14:20 UTC Modified: 2013-09-05 16:47 UTC
From: mfischer@php.net Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.4.19 OS: Linux
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mfischer@php.net
New email:
PHP Version: OS:

 

 [2013-09-05 14:20 UTC] mfischer@php.net
Description:
------------
strtotime() is described as "Parse about any English textual datetime description into a Unix timestamp".

In my case I was providing an integer to $time (maybe it's considered "undefined" behavior) and observed the following behavior: for certain integer input values, it stopped returned false but actually returned value for a time.

Test script:
---------------
<?php
var_dump(strtotime(1359366999));
var_dump(strtotime(1359367000));


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


Actual result:
--------------
bool(false)
int(190309870776)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-09-05 16:47 UTC] derick@php.net
-Status: Open +Status: Not a bug
 [2013-09-05 16:47 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This is working as it should. strtotime() wants a *string* and not an integer. It's just interpreted differently than you expect now:

derick@whisky:~ $ php -r 'var_dump(date_parse(1359367000));'
array(12) {
  'year' =>
  int(7000)
  'month' =>
  bool(false)
  'day' =>
  bool(false)
  'hour' =>
  int(13)
  'minute' =>
  int(59)
  'second' =>
  int(36)
  'fraction' =>
  double(0)
  'warning_count' =>
  int(0)
  'warnings' =>
  array(0) {
  }
  'error_count' =>
  int(0)
  'errors' =>
  array(0) {
  }
  'is_localtime' =>
  bool(false)
}

Instead of parsing a unix timestamp with strtotime(), you should just use the timestamp.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jul 18 17:01:29 2024 UTC