PHP只在生产服务器上使用DateTime时出现了非常奇怪的错误行为


PHP really strange incorrect behaviour with DateTime only on production server

简单地表示为:

    $end   = new 'DateTime();
    $start = clone $end;
    // Remove 30 days from today and set midnight
    $start->sub(new 'DateInterval('P30D'));
    $start->setTime(0, 0);
    var_dump(new 'DateInterval('P30D'));
    var_dump($start, $end); die();

输出(格式良好):

object(DateInterval)#1516 (8)
{ ["y"]=> int(0)
  ["m"]=> int(0)
  ["d"]=> int(30)
  ["h"]=> int(0)
  ["i"]=> int(0)
  ["s"]=> int(0)
  ["invert"]=> int(0)
  ["days"]=> int(0) }
object(DateTime)#1523 (3)
{ ["date"]=> string(19) "2012-06-19 00:00:00"
  ["timezone_type"]=> int(3)
  ["timezone"]=> string(11) "Europe/Rome"
}
object(DateTime)#4682 (3)
{ ["date"]=> string(19) "2012-08-18 02:42:23"
  ["timezone_type"]=> int(3)
  ["timezone"]=> string(11) "Europe/Rome"
}

一个月的错误。。。有线索吗?

编辑:只有在使用时才有正确的行为

$start->modify('-30 days');

注释DateInterval行。

PHP 5.3.2-1ubuntu4.17 with Suhosin-Patch (cli) (built: Jun 19 2012 01:35:33)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
    with XCache v1.3.0, Copyright (c) 2005-2009, by mOo
Server version: Apache/2.2.14 (Ubuntu)
Server built:   Feb 14 2012 18:09:18

自5.3.2以来,已经修复了许多DateTime错误我在5.3.16测试了您的代码,它运行良好,没有重复减法。

反斜杠是什么?据我所见,一切看起来都很好。