php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64369 strtotime() doesn't return false for some invalid formats
Submitted: 2013-03-06 13:47 UTC Modified: 2013-03-06 16:11 UTC
From: gen dot work at gmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.4.12 OS: Ubuntu 12.10
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: gen dot work at gmail dot com
New email:
PHP Version: OS:

 

 [2013-03-06 13:47 UTC] gen dot work at gmail dot com
Description:
------------
strtotime() doesn't return false for some invalid formats.


Test script:
---------------
var_dump(strtotime('invalid_string'));
var_dump(strtotime('-1 monthZ'));
var_dump(strtotime('-1 monthsx'));


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

Actual result:
--------------
bool(false)
int(1360161652)
int(1360201252)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-03-06 14:30 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

That is because they are not invalid. "Z" is a timezone abbreviation:

derick@whisky:~ $ php -r 'var_dump(date_parse("-1 monthZ"));'
array(17) {
  'year' =>
  bool(false)
  'month' =>
  bool(false)
  'day' =>
  bool(false)
  'hour' =>
  bool(false)
  'minute' =>
  bool(false)
  'second' =>
  bool(false)
  'fraction' =>
  bool(false)
  'warning_count' =>
  int(0)
  'warnings' =>
  array(0) {
  }
  'error_count' =>
  int(0)
  'errors' =>
  array(0) {
  }
  'is_localtime' =>
  bool(true)
  'zone_type' =>
  int(2)
  'zone' =>
  int(0)
  'is_dst' =>
  bool(false)
  'tz_abbr' =>
  string(1) "Z"
  'relative' =>
  array(6) {
    'year' =>
    int(0)
    'month' =>
    int(-1)
    'day' =>
    int(0)
    'hour' =>
    int(0)
    'minute' =>
    int(0)
    'second' =>
    int(0)
  }
}

And "SX" is (monthS + X), with X also be a timezone abbreviation:

derick@whisky:~ $ php -r 'var_dump(date_parse("-1 monthsx"));'
array(17) {
  'year' =>
  bool(false)
  'month' =>
  bool(false)
  'day' =>
  bool(false)
  'hour' =>
  bool(false)
  'minute' =>
  bool(false)
  'second' =>
  bool(false)
  'fraction' =>
  bool(false)
  'warning_count' =>
  int(0)
  'warnings' =>
  array(0) {
  }
  'error_count' =>
  int(0)
  'errors' =>
  array(0) {
  }
  'is_localtime' =>
  bool(true)
  'zone_type' =>
  int(2)
  'zone' =>
  int(660)
  'is_dst' =>
  bool(false)
  'tz_abbr' =>
  string(1) "X"
  'relative' =>
  array(6) {
    'year' =>
    int(0)
    'month' =>
    int(-1)
    'day' =>
    int(0)
    'hour' =>
    int(0)
    'minute' =>
    int(0)
    'second' =>
    int(0)
  }
}
 [2013-03-06 14:30 UTC] derick@php.net
-Status: Open +Status: Not a bug
 [2013-03-06 15:28 UTC] gen dot work at gmail dot com
Then following this logic '-1 months' should be parsed as 1 month + S, where S is a timezone abbreviation?
 [2013-03-06 15:49 UTC] derick@php.net
"months" alone is a variant keyword for "month", so no.
 [2013-03-06 16:11 UTC] gen dot work at gmail dot com
True, but this means that for timezone abbreviation "Z" you simply put "1 monthZ", but for "S" you have to write "1 monthsS", which is not so obvious.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 16 00:01:30 2024 UTC