From:             rewilliams at newtekemail dot com
Operating system: Red Hat 6.2; OS X 10.7.5
PHP version:      5.4.12
Package:          Date/time related
Bug Type:         Bug
Bug description:DateTime::createFromFormat() fails randomly when using 
microtime(true) as input

Description:
------------
I have available to me the following PHP versions:

* PHP 5.4.11 running on OS X 10.7.5
* PHP 5.3.15 (Suhosin) running on OS X 10.7.5 (Apple's install)
* PHP 5.3.9 running on Red Hat Enterprise Linux 6.2

I'm able to easily reproduce this on all versions.

Essentially, what's happening is that randomly,
DateTime::createFromFormat() will return false, with the error "Data
missing" as reported by DateTime::getLastErrors(). For testing purposes,
I'm calling it in a loop until I see failure or until one million
iterations have run. On 5.4.11, probably 60% of test runs fail, while it
fails more often on older versions. When it does fail, it seems to be
random how many iterations it gets through - sometimes, just a few
thousand
iterations, other times, mid-way or all the way through.

Notably, in our production environment (running 5.4.11), which is where we
discovered this, we only make the method call one or two times over the
course of an average request.

The parameters I'm passing in my test code are the only ones with which
I've seen this failure. With, say, 'Y-m-d H:i:s' as a format string, it
works every time for me. Related, it doesn't appear to be the microtime()
call itself failing, as I've put that in a loop by itself and not observed
a failure.

Below is an example of the error that's produced when it fails. Note that
in this case, it failed on iteration number 913,371.


[...]
800000
850000
900000
It failed!
i: 913371
bool(false)
array(4) {
  ["warning_count"]=>
  int(0)
  ["warnings"]=>
  array(0) {
  }
  ["error_count"]=>
  int(1)
  ["errors"]=>
  array(1) {
    [10]=>
    string(12) "Data missing"
  }
}

Test script:
---------------
<?php

ini_set('display_errors', true);
ini_set('error_reporting', E_ALL | E_STRICT);

for ($i = 1; $i < 1e6; $i++) {
        if ($i % 50000 == 0) echo $i . "\n";
        
        $foo = \DateTime::createFromFormat('U.u', \microtime(true));
        if (!($foo instanceof DateTime)) {
                echo "It failed!\ni: $i\n";
                var_dump($foo, DateTime::getLastErrors());
                exit;
        } else {
                $foo->format('Y-m-d\TH:i:s.uP');
        } //if-else
} //for

?>

Expected result:
----------------
The DateTime::createFromFormat() call should work every time when given
valid 
parameters.

Actual result:
--------------
The DateTime::createFromFormat() call should works almost every time when
given 
valid parameters, but fails randomly. The reported error is "Data missing".

-- 
Edit bug report at https://bugs.php.net/bug.php?id=64414&edit=1
-- 
Try a snapshot (PHP 5.4):   
https://bugs.php.net/fix.php?id=64414&r=trysnapshot54
Try a snapshot (PHP 5.3):   
https://bugs.php.net/fix.php?id=64414&r=trysnapshot53
Try a snapshot (trunk):     
https://bugs.php.net/fix.php?id=64414&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=64414&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=64414&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=64414&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=64414&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=64414&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=64414&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=64414&r=notwrong
Not enough info:            
https://bugs.php.net/fix.php?id=64414&r=notenoughinfo
Submitted twice:            
https://bugs.php.net/fix.php?id=64414&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=64414&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=64414&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=64414&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=64414&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=64414&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=64414&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=64414&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=64414&r=mysqlcfg

Reply via email to