PHP 5.3.0 DateTime 类的 BUG

观察以下代码:

setTimezone(new DateTimeZone($tz));

// 输出时间
echo $dt->getTimestamp();
echo “\n”;
echo $dt->format(“Y-m-d H:i:s”);
echo “\n”;

// 时间减7天
$dt->sub(new DateInterval(‘P7D’));

// 输出时间
echo $dt->getTimestamp();
echo “\n”;
echo $dt->format(“Y-m-d H:i:s”);
echo “\n”;

// 再次输出时间
echo $dt->getTimestamp();
echo “\n”;
echo $dt->format(“Y-m-d H:i:s”);
echo “\n”;

正确的输出结果应该是:

1303974000
2011-04-28 00:00:00
1303369200
2011-04-21 00:00:00
1303369200
2011-04-21 00:00:00

可是在 PHP 5.3.0 下测试,输出结果为:

1303974000
2011-04-28 00:00:00
1302764400
2011-04-14 00:00:00
1302159600
2011-04-07 00:00:00

真是不可思议!进一步测试发现每次调用 $dt->getTimestamp() 都会使 $dt 往前再减7天。
有在用 DateTime 类的同学们,赶紧把 PHP 版本升级下吧。
PHP 5.3.3 版本下测试正常。

Google 了一下关键词“php 5.3.0 datetime sub bug”,发现这个确实是一个 BUG。
http://bugs.php.net/49059

— EOF —

《PHP 5.3.0 DateTime 类的 BUG》有17个想法

  1. I am also commenting to let you be aware of what a exceptional discovery our girl developed using yuor web blog. She figured out such a lot of details, with the inclusion of what it is like to have an amazing helping heart to make a number of people completely have an understanding of several multifaceted subject matter. You undoubtedly surpassed people’s expectations. Many thanks for presenting these valuable, healthy, educational as well as easy thoughts on the topic to Tanya.

  2. Good blog! I really love how it is easy on my eyes and the data are well written. I am wondering how I might be notified whenever a new post has been made. I have subscribed to your RSS which must do the trick! Have a nice day!

  3. magnificent issues altogether, you simply received a brand new reader. What might you recommend in regards to your publish that you made some days ago? Any certain?

  4. You can definitely see your skills in the work you write. The world hopes for even more passionate writers such as you who are not afraid to say how they believe. At all times follow your heart.

  5. Hey very nice blog!! bikisoe Man .. Excellent .. Amazing .. I’ll bookmark your website and take the feeds also…I’m happy to find a lot of useful information here in the post, we need develop more strategies in this regard, thanks for sharing. . . . . .

  6. Hi! I could have sworn I’ve been to this site before but after checking through some of the post I realized it’s new to me. Anyhow, I’m definitely glad I found it and I’ll be book-marking and checking back frequently!|

  7. Dies betrifft insbesondere die vom Teilnehmer geführte Emailadresse, um wichtige Informationen und Änderungen der Dienste vom Portalbetreiber per E-Mail-Übermittlung die vom Nutzer aktuell, hinterlegten Emailadresse mitgeteilt zu bekommen.

  8. Für unser Einjähriges haben amateure web cams wir auch schon etwas geplant.Als ich mich nach zwei Tagen verabschiedete, sagte : Was sind schon sechzig live Kilometer für eine heiße Liebe?.Der erste Mann streckte webcam chat live plötzlich eine Hand nach mir aus und befühlte den Stoff der Bluse, die ich trug.

发表评论

电子邮件地址不会被公开。 必填项已用*标注