1
这工作:DateTime的方法链问题
$aWeekAfterDate = new DateTime();
$aWeekAfterDate->modify('+1 week');
$aWeekAfterDate->format('d.m.Y');
但这:
$aWeekAfterDate = new DateTime();
$aWeekAfterDate->modify('+1 week')->format('d.m.Y');
给了我这个错误:
Fatal error: Call to a member function format() on a non-object in ... on line ...
Fatal error (shutdown): Call to a member function format() on a non-object in ... on line ...
我已经看过了文档中的DateTime::modify方法它的回报值是这样的:
Returns the DateTime object for method chaining or FALSE on failure.
为什么方法链不起作用?
我使用PHP版本5.2.6。
只介绍我怎么能不看到这一点。 – 2011-03-31 09:14:05
容易被忽视,除非你之前被它蜇过 – 2011-03-31 09:32:04